程序如下://借助RandomAccessFile把文件存入byte数组中
import java.io.*;
class FileToByteArrayByRandomAccessFile
{
  public static void main(String args[])
   {
    try
     {
        File inputFile=new File("D:/mxjxj/mail/abc.txt");
        RandomAccessFile raFile=new RandomAccessFile(inputFile,"r");
        byte[] byteArray;
        byteArray=new byte[(int)inputFile.length()];
        raFile.readFully(byteArray);
        System.out.println(byteArray);
        raFile.close();
      }     catch(FileNotFoundException e)
       {System.err.println("FileStreanTest:"+e);}
     catch(IOException e)
       {System.err.println("FileStreamTest:"+e);}
}
}

解决方案 »

  1.   

    你打印的是地址:
    System.out.println(byteArray);用
    String a=new String(byteArray);
    System.out.println(a);
      

  2.   

    可以这样写:运行过没问题但是在oracle jdeveloper中不能显示汉字
    import java.io.*;
    class FileToByteArrayByRandomAccessFile{
      public static void main(String args[])
       {
        try
         {
            File inputFile=new File("D:/b.txt");
            RandomAccessFile raFile=new RandomAccessFile(inputFile,"r");
           // byte[] byteArray;
            String str;
          //  byteArray=new byte[(int)inputFile.length()];
            str=raFile.readLine();
            //raFile.readFully(byteArray);
            System.out.println(str);
            raFile.close();
          }     catch(FileNotFoundException e)
           {System.err.println("FileStreanTest:"+e);}
         catch(IOException e)
           {System.err.println("FileStreamTest:"+e);}
    }}