package xxxx;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class Demo1 {
public static void main(String[] args) throws InterruptedException, IOException {
BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\1678351064qq.com\\Desktop\\11\\a\\a1.txt"));
BufferedWriter bw = new BufferedWriter(new FileWriter("C:\\Users\\1678351064qq.com\\Desktop\\11\\a\\a2.txt"));
char[] ch= new char[1024];
int len=0;
while ((len=br.read(ch)) != -1) {
bw.write(ch,0,len);
bw.flush();
}
br.close();
bw.close();
//程序运行后若是发现复制文本内容乱码,则说明编码和解码格式不一致造成的. 以下有两种解决办法:
}
}
1,复制的文本在创建时要保存为和下图编译工具设定的编码格式一致
2,使用转换流将文件编码格式转化为UTF-8格式
//使用转换流将电脑中默认GBK编码格式文件读取,再以UTF-8格式输出,得到不乱码的文档
package xxxx;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.zip.InflaterInputStream;
public class Demo1 {
public static void main(String[] args) throws InterruptedException, IOException {
OutputStreamWriter z = new OutputStreamWriter(new FileOutputStream("C:\\Users\\1678351064qq.com\\Desktop\\11\\a\\a3.txt"),"UTF-8");
InputStreamReader zh = new InputStreamReader(new FileInputStream("C:\\Users\\1678351064qq.com\\Desktop\\11\\a\\a1.txt"),"GBK");
char[] ch= new char[1024];
int len=0;
while ((len=zh.read(ch)) != -1) {
z.write(ch,0,len);
}
z.close();
}
}