先读到一个byte数组里面,然后用String的构造器构造,第一个参数为此数组,第二个参数为字符编码
QQ1818477欢迎交流

解决方案 »

  1.   

    试试下面程序
    import java.io.*;public class ReadFile {
        public static void main (String[] args) {
            // Create file
            if (args.length!=1){
                System.out.println("Usage: java ReadFile filename");
                return ;
            }
            File file = new File(args[0]);
            StringBuffer  sb = new StringBuffer ();        try {
                // Create a buffered reader to read each line from a file.
                BufferedReader in = new BufferedReader(new FileReader(file));
                 // Read each char and chain.
                int i;
                while ( (i=in.read())!= -1 ) {
                    sb.append((char)i);
                }
                // Close the buffered reader, which also closes the file reader.
                in.close();        } catch (FileNotFoundException e1) {
                // If this file does not exist
                System.err.println("File not found: " + file);
            } catch (IOException e2) {
                // Catch any other IO exceptions.
                e2.printStackTrace();
            }
            System.out.println(" content of '"+args[0]+"'");
            System.out.println(sb.toString());    }
    }
      

  2.   

    看看  FileInputStream  RandomAccessFile 类
      

  3.   

    simple:
    FileInputStream fis=new FileInputStream(filepath);
    byte[] b=new byte[fis.available()];
    fis.read(b);
    String myString=new String(b);
      

  4.   

         修改闹闹一些东西大概会比较好
         try {
                // Create a buffered reader to read each line from a file.
                BufferedReader in = new BufferedReader(new FileReader(file));
                // Read each char and chain.
                
                String temp;
                while ( (temp=in.readLine())!= null ) {
                    sb.append(temp);
                }
                // Close the buffered reader, which also closes the file reader.
                in.close();