继续研究文件IO。
作用是用System.in输入一个文件路径,然后打印文件里的所有行。
而且虽然没仔细检查过,哦不就是因为没检查过,所以肯定不够健壮。
1 import java.io.*; 2 import java.util.Scanner; 3 4 public class test { 5 public static void main(String[] args) { 6 Scanner input = new Scanner(System.in); 7 String file = input.nextLine(); 8 9 printContent(file, System.out); 10 } 11 12 public static void printContent(String file, PrintStream out) { 13 try { 14 BufferedReader input = new BufferedReader(new FileReader(file)); 15 16 String s = null; 17 while ((s = input.readLine()) != null) { 18 out.println(s); 19 } 20 } catch (IOException e) { 21 e.printStackTrace(); 22 } 23 } 24 }