package org.pdool.iodoc;
import java.io.*;
/**
* 拷贝文件
*
* @author 香菜
*/
public class CopyFileWithBuffer {
public static void main(String[] args) throws Exception {
String inFilePath = "D:\\wechat\\A.txt";
String outFilePath = "D:\\wechat\\B.txt";
try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream(inFilePath));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(outFilePath))) {
byte[] b = new byte[1024];
int off = 0;
while ((off = bis.read(b)) > 0) {
bos.write(b, 0, off);
}
}
}
}
3、获取键盘输入
import java.util.Scanner;
public class TestScanner {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNextLine()){
System.out.println(scanner.nextLine());
}
}
}