java在AIX的乱码问题

jayli426 2008-05-08 04:18:12
package test;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class WriteFile {

public static void createFile(String fileName) {
try {

//String str1 = new String(fileName.getBytes("ISO8859_1"),"gb2312");
FileOutputStream fw = new FileOutputStream(fileName);

BufferedWriter stdout;

stdout = new BufferedWriter(new OutputStreamWriter(fw,"gb2312"));
String str= "可可在测试aaaaaaaaaaaaaaaa";
stdout.write(str);
stdout.flush();
fw.close();
stdout.close();


} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}

public static void main(String[] args) {

String encoding = System.getProperty("file.encoding");
System.out.println("file.encoding============="+encoding);


createFile(args[0]);
String str = "/home/topetl/lzz/东东VVVV.txt";
createFile(str);

}
}



将这个类单独打成了一个jar 包,在AIX下执行结果如下

[/home/topetl/lzz] java -jar ./createFile.jar /home/topetl/lzz/哦哦LL.txt
file.encoding=============ISO8859-1
[/home/topetl/lzz] ls -ltr
total 56
-rw-r----- 1 topetl etl 49 Apr 15 04:41 lock.out
-rwxr-x--x 1 topetl etl 612 Apr 15 04:51 sms.sh
-rwxrwxrwx 1 topetl etl 6 Apr 15 04:58 abc
drwxr-x--- 2 topetl etl 256 Apr 19 06:52 aaaa
-rw-r----- 1 topetl etl 71 May 8 09:54 ABC.AVL
-rw-r----- 1 topetl etl 1256 May 8 16:02 createFile.jar
-rw-r--r-- 1 topetl etl 26 May 8 16:02 哦哦LL.txt
-rw-r--r-- 1 topetl etl 26 May 8 16:02 ??VVVV.txt
[/home/topetl/lzz] cat ??VVVV.txt
可可在测试aaaaaaaaaaaaaaaa[/home/topetl/lzz] cat 哦哦LL.txt
可可在测试aaaaaaaaaaaaaaaa[/home/topetl/lzz]

如果文件名是传入的,就是正常
但是我自己在java中写的就是不正常的

文件中数据也是正常,但是如果不经过
“stdout = new BufferedWriter(new OutputStreamWriter(fw,"gb2312"));”
这样一个编码处理,也会是不正常的,之前也试过了
但是对于文件名该如何处理呢?

请大虾指教啊
...全文
297 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
a_nuo 2008-05-09
  • 打赏
  • 举报
回复
String str2=new String(filePath.getBytes("ISO8859-1"),"gb2312");
String str1 = new String(fileName.getBytes("ISO8859-1"),"gb2312");
File pathName==new File(str2);
File fileNamestr=new File(pathName,str1);
试一试
jayli426 2008-05-08
  • 打赏
  • 举报
回复
怎么转啊,大虾,能够提供一个思路吗
a_nuo 2008-05-08
  • 打赏
  • 举报
回复
文件名是中文的话可能需要编码转换
a_nuo 2008-05-08
  • 打赏
  • 举报
回复
你把文件路径和文件名称分开,构建File对象试一试

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧