import java.util.*;
import java.io.*;public class iotest {

public static void main(String[] args)throws IOException {
File read = new File("member.txt");
Scanner reader =new Scanner(read);
String inputLine; while (reader.hasNextLine()){
inputLine=reader.nextLine();
System.out.println(inputLine);

}
}
}
如果有多个文件,我应该怎么写呢?

解决方案 »

  1.   

    import java.util.*;
    import java.io.*;public class iotest {

    public static void main(String[] args)throws IOException {
              
             File d = new File("你的文件夹路径");
             String[] fileNames = d.list();
             
             for (int i=0; i < fileNames.length ; i++) {  
    File read = new File(fileNames[i]);
    Scanner reader =new Scanner(read);
    String inputLine; while (reader.hasNextLine()){
    inputLine=reader.nextLine();
    System.out.println(inputLine);

    }
     
    }
    }