java:从txt中读取每一行,并包装成json

package readFromTxt;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class ReadFromTxt {

public static void main(String[] args) {
// TODO Auto-generated method stub
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader("C:\\EWS\\readFromTxt\\index.txt"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String str = "[";
String temp="";
try {
while(null != (temp = br.readLine())){
str +="{name:"+"\""+temp+"\""+", ticked: false},";
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(str+"]");
try {
br.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

posted @ 2017-12-15 17:35  董永辉Bruno  阅读(2019)  评论(0编辑  收藏  举报