我已经有4个class 和txt文件, 如何load txt里的内容,以下是我一部分的code
public static void main(String[] args) {
FormMovieManager form = new FormMovieManager();
        form.setVisible(true);
        
       form.run();
        
}
public void run()
{
final String DATA_FILE_NAME = "movieData.txt";
int input = -1;MovieDataReader file;
MovieManager MM=new MovieManager();
        int numMovie = 0;          try {
         // Load book data         file = new MovieDataReader(DATA_FILE_NAME);
         numMovie = loadData(MM, file);
  
          while (input != 0);
     } catch (IOException ioe) {
         System.err.println("Error: " + ioe.getMessage());
         System.exit(0);
      } 
    
   }
 private void listMovie(MovieManager MM) {
      Movie movie;
      for (int i = 0; i < MM.size(); i++) {
         movie = MM.getMovie(i);}
           
 }
   private int loadData(MovieManager MM, MovieDataReader dataFile)
       throws IOException {
    Movie movie = null;
    int count = 0;    do {
       // Initialize book
       movie= null;       // Get next book
     movie = dataFile.next();       // If not null, add to library
       if (movie != null) {
          MM.addMovie(movie);
          count++;
       }
    } while (movie != null);    return count;
 }}

解决方案 »

  1.   

    java基础部分有关于I/O的一块,你看看吧,那里很有用的
      

  2.   

    只要你有个TXT的文件,以下这个类就完全可以实现你的要求
    import java.io.*;    
    import java.util.Scanner;    
       
    public class ScanXan {    
        public static void main(String[] args) throws IOException {    
             Scanner s = null;    
            try {    
                 s = new Scanner(new BufferedReader(new FileReader("c:\\new.txt")));    
                //使用字符串jdk作为分隔符    
                 s.useDelimiter("jdk");    
                while (s.hasNext()) {    
                     System.out.println(s.next());    
                 }    
             } finally {    
                if (s != null) {    
                     s.close();    
                 }    
             }    
         }    
    }