把资料从ANSI转成utf-8
把文件从ANSI转成utf-8
package liu;
import java.io.*;
public class FileProcess {
/**
* @param args
*/
public static void main(String[] args) {
FileInputStream fis = null;
FileOutputStream fos = null;
try{
fis = new FileInputStream(new File("f:\\FromNC.txt"));
fos = new FileOutputStream(new File("f:\\b.txt"));
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
String str = new String(buffer, "GBK");
fos.write(str.getBytes("utf-8"));
}catch(Exception e){
e.printStackTrace();
}finally{
if(fis != null){
try{
fis.close();
}catch(Exception e){
}
}
if(fos != null){
try{
fos.close();
}catch(Exception e){
}
}
}
}
}
package liu;
import java.io.*;
public class FileProcess {
/**
* @param args
*/
public static void main(String[] args) {
FileInputStream fis = null;
FileOutputStream fos = null;
try{
fis = new FileInputStream(new File("f:\\FromNC.txt"));
fos = new FileOutputStream(new File("f:\\b.txt"));
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
String str = new String(buffer, "GBK");
fos.write(str.getBytes("utf-8"));
}catch(Exception e){
e.printStackTrace();
}finally{
if(fis != null){
try{
fis.close();
}catch(Exception e){
}
}
if(fos != null){
try{
fos.close();
}catch(Exception e){
}
}
}
}
}