我的代码如下: try
{
FileOutputStream fo = new FileOutputStream("/home/root/1");
fo.write("你好abc".getBytes());
fo.close();
}
catch (IOException e)
{
e.printStackTrace();
}听说是系统字符集的问题,通过设置JAVA的系统属性可以解决,但我修改代码如下还是没有任何改变:
try
{
System.setProperty("file.encoding", "GBK");
System.setProperty("user.language", "zh");
Properties pro = System.getProperties();
pro.list(System.out); // <--输入的值显示系统属性已被改变 FileOutputStream fo = new FileOutputStream("/home/maxchou/1");
fo.write("你好abc".getBytes());
fo.close();
}
catch (IOException e)
{
e.printStackTrace();
}
{
FileOutputStream fo = new FileOutputStream("/home/root/1");
fo.write("你好abc".getBytes());
fo.close();
}
catch (IOException e)
{
e.printStackTrace();
}听说是系统字符集的问题,通过设置JAVA的系统属性可以解决,但我修改代码如下还是没有任何改变:
try
{
System.setProperty("file.encoding", "GBK");
System.setProperty("user.language", "zh");
Properties pro = System.getProperties();
pro.list(System.out); // <--输入的值显示系统属性已被改变 FileOutputStream fo = new FileOutputStream("/home/maxchou/1");
fo.write("你好abc".getBytes());
fo.close();
}
catch (IOException e)
{
e.printStackTrace();
}
bw.write("阿土");
bw.close();
home/root/1--->路径确实存在吗?且你有写权限吗?
不知道你有什么问题?
windows列出的System.getProperties()中
file.encoding=GBK
user.language=zh而linux列出的System.getProperties()中
file.encoding=UTF-8
user.language=en这种情况下运行程序后生成的文件分别是GBK编码和UTF-8编码,如何在JAVA中统一其输出的编码。