public class ChangeEncoding { |
| public static void changeEncoding (String inEncoding, String outEncoding, |
| String inFileName, String outFileName) throws IOException { |
| BufferedReader reader = new BufferedReader( |
| new FileInputStream(inFileName), inEncoding)); |
| BufferedWriter writer = new BufferedWriter( |
| new FileOutputStream(outFileName), outEncoding)); |
| while ((s = reader.readLine()) != null ) { |
| writer.write(s, 0 , s.length()); |
| public static void main(String[] args) { |
| changeEncoding( "GBK" , "UTF-8" , "gbk.txt" , "utf8.txt" ); |
| } catch (IOException e) { |
| System.out.println( "转换失败,原因:" + e.getMessage()); |
转载于:https://www.cnblogs.com/majian714/archive/2011/10/09/2204180.html