linux环境上传wincsv文件,解决linux环境下上传文件及读取csv文件乱码

昨天弄了短信运营工具,开始时候本机测试一切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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值