publicstaticvoidmain(String[]args)throwsIOException{//TODOAuto-generatedmethodstubFilefile=newFile("F://svn//Test.properties");InputStreamio=newFileInputStream(file);byte...
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
File file=new File("F://svn//Test.properties");
InputStream io=new FileInputStream(file);
byte[] buf=new byte[(int)file.length()];
io.read(buf);
String str=new String(buf);
byte[] str1=str.getBytes();
//String str="u8fd9u662fu4e00u4e2au5bc6u7801";
System.out.println(str.length());
System.out.println("file.encoding:" + System.getProperty("file.encoding"));
String st=transaction(str1);
System.out.println(st);
}
protected static String transaction(byte[] filename){
String str=null;
try {
str=new String(filename,"UTF-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return str;
}
就这样一个代码,为什么从文件中读取得到的String,查看length得到的是36,转码得不到预期结果。
//String str="u8fd9u662fu4e00u4e2au5bc6u7801";
而直接写在代码里面的String,length是6,转码成功为“这是一个密码”
展开
最后
以上就是激动向日葵最近收集整理的关于java 文件 转码_java文件读取内容转码的全部内容,更多相关java内容请搜索靠谱客的其他文章。
发表评论 取消回复