java的程序在linux下运行写中文到文件中就是乱码,但是在win2000下是好的
代码如下,为何啊?
public boolean WriteTxtLogFile(int year,int month,int day,String strInLog)
{
try{
String logString=""; //日志记录字符串
//创建日志目录
String strOut = Mkdir("log");
if (strOut != null)
System.out.println();
String szTodayXMLDoc = year + "-" + month + "-" + day + ".log";
File file = new File("log/" + szTodayXMLDoc);
FileOutputStream foo = null;
if (! (file.exists())) {
file.createNewFile(); //如果文件不存在,创建此文件
}
foo = new FileOutputStream("log/" + szTodayXMLDoc, true); //以append方式
logString=System.getProperties().getProperty("line.separator");
logString = strInLog+System.getProperties().getProperty("line.separator");
foo.write(logString.getBytes(), 0, logString.length()); //写入日志字符串
foo.close();
return true;
}
catch (Exception e)
{
System.out.println(e.getMessage());
return false;
}
}