java 文件上传中如何获取上传文件的字符集编码
展开全部
看看这篇
http://www.javaeye.com/topic/266501
还有这个
http://blog.csdn.net/crackcell/archive/2007/11/22/1898128.aspx
这个是jchardet的地址
http://sourceforge.net/projects/jchardet/
也有人写了用getEncoding
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
public class FileCharset {
public static void main(String[] args) throws FileNotFoundException {
InputStreamReader isr = new InputStreamReader(new FileInputStream(
"Service02.asp"));
System.err.println(isr.getEncoding());
BufferedReader br = new BufferedReader(isr);
}
}
但是不起作用
getEncoding gives you the encoding the reader is using, not what the file is
using. The problem is that there isn't anything in the file that says what
encoding it is using. You can look at some byte patterns to try to
determine whether it's UTF-8, UTF-16BE, or whatever but there's no perfect
rule for it.
http://www.javaeye.com/topic/266501
还有这个
http://blog.csdn.net/crackcell/archive/2007/11/22/1898128.aspx
这个是jchardet的地址
http://sourceforge.net/projects/jchardet/
也有人写了用getEncoding
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
public class FileCharset {
public static void main(String[] args) throws FileNotFoundException {
InputStreamReader isr = new InputStreamReader(new FileInputStream(
"Service02.asp"));
System.err.println(isr.getEncoding());
BufferedReader br = new BufferedReader(isr);
}
}
但是不起作用
getEncoding gives you the encoding the reader is using, not what the file is
using. The problem is that there isn't anything in the file that says what
encoding it is using. You can look at some byte patterns to try to
determine whether it's UTF-8, UTF-16BE, or whatever but there's no perfect
rule for it.
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
呵呵,这个问题,一句话:微软是美国人的,不是中国人的。
参考资料: 百度一下
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
人的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询