环境:j2se 1.42+tomcat5.0.28+linux as 3+oracle9i2现像就是:从数据取得字符串数据,然后写成一个JS文件,写入的代码:
this.nfile = new FileWriter(NewFile);/**
* 添加一个字符串到文件
* @param s 要添加的内容
*/
public void addTXT(String s){
char buf[] = new char[s.length()];
s.getChars(0,s.length(),buf,0);
try{
if (this.getNfile()!=null)
this.getNfile().write(buf);
}catch(IOException e){
CLog.addError("文件写入出错:"+e.getMessage());
}catch(Exception e){
CLog.addError("文件写入出错:"+e.getMessage());
}
}但在LINUX下运行时,比如字符串是search.jsp,但写到JS后打开来看只有search.js,那个p没掉了
但在WINDOW下就不会这样,WIN的环境是:tomcat5.0.28+jdk1.4+同一个数据库为什么会这样,有没有别的方法写入文件会更稳定?
this.nfile = new FileWriter(NewFile);/**
* 添加一个字符串到文件
* @param s 要添加的内容
*/
public void addTXT(String s){
char buf[] = new char[s.length()];
s.getChars(0,s.length(),buf,0);
try{
if (this.getNfile()!=null)
this.getNfile().write(buf);
}catch(IOException e){
CLog.addError("文件写入出错:"+e.getMessage());
}catch(Exception e){
CLog.addError("文件写入出错:"+e.getMessage());
}
}但在LINUX下运行时,比如字符串是search.jsp,但写到JS后打开来看只有search.js,那个p没掉了
但在WINDOW下就不会这样,WIN的环境是:tomcat5.0.28+jdk1.4+同一个数据库为什么会这样,有没有别的方法写入文件会更稳定?
有点心得:和Linux的编码方式非常有关系.试试不同的Linux版本
也没报错,写入一切正常,但打JS文件就是少一个字符,对数据库更新一下,重写,还是一样
try{
if (this.getNfile()!=null)
this.getNfile().write(s);
}catch(IOException e){
CLog.addError("文件写入出错:"+e.getMessage());
}
}:)
public void addTXT(String s){
try{
if (this.getNfile()!=null)
this.getNfile().write(s);
}catch(IOException e){
CLog.addError("文件写入出错:"+e.getMessage());
}
}
但仍然会这样但只要把LINUX的LANG设为GBK,就不会了,的确是很奇怪
我测试了一下:再设回去,又会那样....无语现在已改成GBK,希望再也不会少字符....以前用DOM4J写XML也出现过这个问题,莫名其妙的少掉一个字符....
难道也是...继续关注与测试
修改文件
/etc/sysconfig/i18n 里的 LANG
this.nfile = new FileWriter(NewFile,true);你可以尝试一下这样:
BufferedWriter out = new BufferedWriter(new FileWriter(NewFile,true));