import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner;
public class Test {
public static void main(String[] args) throws Exception {
//使用Scanner类读取文件In.txt
Scanner in = new Scanner(new File("E:\\In.txt"));
//重定向标准输出,创建PrintStream输出流
PrintStream ps = new PrintStream(new FileOutputStream("E:\\Out.txt"));
System.setOut(ps); //将标准输出重新定向到ps输出流
while (in.hasNext()) {
System.out.println(in.nextInt() + "\n");
}
}
}
用fileinputstream,,读取数字字符串然后integer包装
直接用工具类搞定!