昨天弄了短信运营工具,开始时候本机测试一切ok的,但是放到linux环境上就是不行,读取的csv文件为乱码,
找了一堆堆的资料还是不行。我的机器环境是win7系统。
String realPath = WebApplicationConstant.WEB_ROOT +
SpringPropertyConfigurer.getContextProperty("manage.path.tmp");
File fileDir = FileHelper.createDirIfNoExist(realPath);
int maxsize = Integer.parseInt(SpringPropertyConfigurer.getContextProperty("manage.file.available.size.profile"));
MultipartRequest mr = new MultipartRequest(request, realPath, maxsize, "UTF-8");
String realPath = WebApplicationConstant.WEB_ROOT + SpringPropertyConfigurer.getContextProperty("manage.path.tmp");
BufferedReader reader;
try {
FileReader fr = new FileReader(realPath + uploadfile);
reader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(realPath + uploadfile)), fr.getEncoding()));
reader = new BufferedReader(fr);
String str = null;
我采用的是动态获取文件编码,之后按照这个编码读取文件,但没什么用!!!
linux系统编码是utf-8的,我win7系统编码默认是UTF-8,程序编码是UTF-8,jvm是GBK的,所以我本地上传
ansi文件之后,fr.getEncoding 获取的是当前运行他的工具。比如我jvm gbk 获取的就是gbk。
但是我更改jvm 运行编码为UTf-8 fr.getEncoding打印出的UTF-8
十分怪异的问题,希望高手明确指点下非常感谢!!!
linux环境下tomcat设置如下方式,即可上传默认的ansi文件编码,存到数据库不会乱码!!!!!!
# add GBK file encoding
JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF-8"
注意:eclipse工具默认的-Dfile.encoding=GBK。
注意:cos上传方式只是对文件名进行编码,内容没有管。
获取系统编码
String encoding = System.getProperty("file.encoding");
System.out.println("你的操作系统所用的编码为:"+encoding)