网站发布后 用java代码更改了tomcat下该项目下的某个文件的内容 事实证明修改成功了
但是网页上就显示不出这个内容了。需要手动打开这个文件然后随便改点再保存 才可以在网页上显示出来
这是为什么哇?? 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();
但是网页上就显示不出这个内容了。需要手动打开这个文件然后随便改点再保存 才可以在网页上显示出来
这是为什么哇?? 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();
flush? 还是flash? 这个文件里的内容是用于存放flash的数据的.
刚百度了flush() 原来如此 我试试看
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();
}
}
}
Writer outTxt = new OutputStreamWriter(new FileOutputStream(file,false), "GBK");之前是utf-8 改成 GBK 就OK了