public static void main(String[] args) throws IOException {
//demo1();
//demo2();
BufferedReader br = //更高效的读
new BufferedReader(new InputStreamReader(new FileInputStream("utf_8.txt"),"utf-8"));
BufferedWriter bw =//更高效的写
new BufferedWriter(new OutputStreamWriter(new FileOutputStream("gbk.txt"),"gbk"));
int c;
while ((c=br.read()) !=-1) {
bw.write(c);
}
br.close();
bw.close();
}
public static void demo2() throws UnsupportedEncodingException, FileNotFoundException, IOException {
//指定码表读写字符
InputStreamReader isr=new InputStreamReader(new FileInputStream("utf_8.txt"),"utf-8");
OutputStreamWriter osw =new OutputStreamWriter(new FileOutputStream("gbk.txt"),"gbk");
int c ;
while ((c =isr.read()) !=-1) {
osw.write(c);
}
isr.close();
osw.close();
}
public static void demo1() throws FileNotFoundException, IOException {
FileReader fr =new FileReader("utf_8.txt");
FileWriter fw =new FileWriter("gbk.txt");
int a ;
while ((a =fr.read())!=-1) {
fw.write(a);
}
fr.close();
fw.close();
}
//demo1();
//demo2();
BufferedReader br = //更高效的读
new BufferedReader(new InputStreamReader(new FileInputStream("utf_8.txt"),"utf-8"));
BufferedWriter bw =//更高效的写
new BufferedWriter(new OutputStreamWriter(new FileOutputStream("gbk.txt"),"gbk"));
int c;
while ((c=br.read()) !=-1) {
bw.write(c);
}
br.close();
bw.close();
}
public static void demo2() throws UnsupportedEncodingException, FileNotFoundException, IOException {
//指定码表读写字符
InputStreamReader isr=new InputStreamReader(new FileInputStream("utf_8.txt"),"utf-8");
OutputStreamWriter osw =new OutputStreamWriter(new FileOutputStream("gbk.txt"),"gbk");
int c ;
while ((c =isr.read()) !=-1) {
osw.write(c);
}
isr.close();
osw.close();
}
public static void demo1() throws FileNotFoundException, IOException {
FileReader fr =new FileReader("utf_8.txt");
FileWriter fw =new FileWriter("gbk.txt");
int a ;
while ((a =fr.read())!=-1) {
fw.write(a);
}
fr.close();
fw.close();
}