81,092
社区成员
发帖
与我相关
我的任务
分享
JSONArray jsonArray2 = JSONArray.fromObject(Hotels);
String path = System.getProperty("user.dir").replace("\\", "/") +"/../webapps/ChinaTravelServiceZJ";
path =path+"/data.txt";
File file = new File(path);
Writer outTxt = null;
try {
outTxt = new OutputStreamWriter(new FileOutputStream(file,false), "UTF-8");
} catch (UnsupportedEncodingException e1) {
e1.printStackTrace();
}
System.out.println(jsonArray2.toString());
System.out.println(path);
outTxt.write(jsonArray2.toString());
outTxt.close();
public class Test {
public static void main(String[] args) throws Exception{
File file = new File("D:\\workspace\\test\\a.jad");
Writer outTxt = new OutputStreamWriter(new FileOutputStream(file,false), "GBK");
outTxt.write("中文测试1");
outTxt.flush();
outTxt.close();
System.out.println("===============writer over==============");
T t = new T();
t.start();
Thread.sleep(10000);
// BufferedReader reader = new BufferedReader(new FileReader(file));
// System.out.println(reader.readLine());
}
}
class T extends Thread{
@Override
public void run() {
try {
File file = new File("D:\\workspace\\test\\a.jad");
BufferedReader reader = new BufferedReader(new FileReader(file));
System.out.println(reader.readLine());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}