qinuxman android读文件从字节码变成字符再把字符变回字节码写成文件这么写为什么不对
File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator+"download/ads/81/icon.png");
InputStream f1;
try {
f1 = new FileInputStream(f);
InputStreamReader in;
try {
in = new InputStreamReader(f1,"utf8");
char c1[] = new char[1024*100] ;
try {
int ch;
StringBuffer temp = new StringBuffer();
while((ch = in.read())!=-1)
temp.append((char)ch);
CompaniesUtilist.photo= temp.toString();
//以上把文件变成字符串,下面把字符串变回文件
File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+ File.separator+"test/io.png") ;
FileOutputStream out1;
try {
out1 = new FileOutputStream(f);
OutputStreamWriter out = new OutputStreamWriter(out1,Charset.forName("utf-8"));
try {
//out.append(CompaniesUtilist.photo);
out.write(CompaniesUtilist.photo);
out.close() ;
System.out.println("Filesize="+f.length());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
[解决办法]
utf8改成iso-8859-1就OK了