本文共 650 字,大约阅读时间需要 2 分钟。
public class FileCopy { public static void main(String[] args) throws IOException { // 输入流 FileInputStream fileInputStream = new FileInputStream(new File("D:\\abc.txt")); // 输出流 FileOutputStream fileOutputStream = new FileOutputStream("D:\\abc(字节方式).txt"); // 缓冲区(每次读10字节) byte[] bytes = new byte[10]; // 写到文件中 int length; while((length = fileInputStream.read(bytes)) != -1){ System.out.println(new String(bytes)); fileOutputStream.write(bytes, 0, length); } // 关闭流 fileOutputStream.close(); fileInputStream.close(); }}
转载地址:http://abrqz.baihongyu.com/