reader1=new BufferedReader (new FileReader(path+"1\\"+file[i]));
           while((line=reader1.readLine())!=null){
             oldMap.put(line,"a");
             System.out.println(line);
           }
           reader1.close();

解决方案 »

  1.   

    不过这个只能一行一行的读取
     假如是好像数据的话 可以换成DataInpuStream.
      

  2.   

    下面这样就可以把一个文件中的内容读到一个字符串中:String Content="";
    String htmPath="c:\\file.in";
    RandomAccessFile fhtm=new RandomAccessFile(htmPath,"r");
    long filePointer=0;
    long length=fhtm.length();
    while(filePointer<length)
    {
       Content=Content + fhtm.readLine();
       filePointer=fhtm.getFilePointer();
    }
    fhtm.close();
      

  3.   

    谢谢大家的帮助,其实没有这么麻烦,我就是想把一个文件里的东西全部读到一个string里,
    比如说原来
    String str = "I love you \n \n You love me??\n\n"现在我只是把"I love you \n \n You love me??\n\n"这些内容放在一个叫file.in的文件里,想要用BufferedReader, FileReader和readLine等打开这个文件,然后把这些字符全部放到str里,我试过上面的这些方法,好想都不是很好,请大家再帮帮忙,谢谢了!
      

  4.   

    import java.io.*;public class FileIO{
    public static void main(String[] args) throws IOException{
    FileReader fr = new FileReader("C:/file.in");
    int i = 0;
    String str = "";
    while((i = fr.read())!=-1)
    str += (char)i;
    fr.close();
    System.out.println(str);
    }
    }
      

  5.   

    谢谢楼上这位大哥的程序,可是我还是有一个小问题,那就是上面的程序只能读入一个叫file.in的文件,如果我想读入java WordPuzzle *.in 
    就是任何一个不知道名字的文件,应该怎么做哪? 是不是要用args[0]来表示这个文件? 
    怎样用FileReader来读取args[0]哪? 我试了很多种方法都不行,报错说" cannot resolve symbol".我是在Unix环境下编程的.
    很急,请各位高手再麻烦一下,感激不尽!