FileInputStream 与 FileOutputStream (txt,docx等 都不会出现乱码)
public static void main(String[] args) throws Exception {
File file = new File("D:\\htmTopdf\\55.txt");
File file2 = new File("D:\\htmTopdf\\aa.txt");
// 数据读取的对象封装
FileInputStream fis = new FileInputStream(file.getPath());
// 数据写入对象封装
FileOutputStream fos = new FileOutputStream(file2.getPath());
// 数据的读写
byte[] bys = new byte[1024];
int len = 0;
while ((len = fis.read(bys)) != -1) {
fos.write(bys, 0, len);
}
// 关闭流
fis.close();
fos.close();
}
高效 BufferedInputStream与 BufferedOutputStream(txt,docx等 都不会出现乱码)
public static void main(String[] args) throws Exception {
File file = new File("D:\\htmTopdf\\55.jpg");
File file2 = new File("D:\\htmTopdf\\aa.jpg");
// 数据读取对象封装
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file.getPath()));
// 数据写入对象封装
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file2.getPath()));
// 数据读写操作
byte[] bys = new byte[1024];
int len = 0;
while ((len = bis.read(bys)) != -1) {
bos.write(bys, 0, len);
}
// 关闭流
bos.close();
bis.close();
}
参考:https://www.cnblogs.com/fuck1/p/5373679.html
1036

被折叠的 条评论
为什么被折叠?



