/*
 * 用RandomAccessFile将一个文件读取出来保存进一个字符串里
         * inputPath是文件的路径
         * 函数返回为读取出来的字符串
 */
public static String class2String(String inputPath) throws Exception{
String content = null;
RandomAccessFile file = new RandomAccessFile(inputPath,"r");
//类文件大小要在Integer.MAX_VALUE之内
System.out.println(file.length());
byte[] bytes = new byte[(int) file.length()];
System.out.println("    字节数组的长度      " +bytes.length);
int flag = 0;
flag = file.read(bytes);
System.out.println("将class文件读进字节数组后,数组的长度  " +bytes.length);
content = new String(bytes);
System.out.println("将字节数组转化为字符串后,字符串的长度   " +content.length());
return content;
}用上面的方式,将文件的内容读取出来,存进一个字符串
当传进来的是一个.txt之类的字符文件,则结果正常
当传进来的是一个.class的字节文件时,读取到的字符串就有问题
比如这个函数里面插进去的几条测试输出(我传进去一个.class字节文件)
-------
字节数组的长度      1732
将class文件读进字节数组后,数组的长度  1732
将字节数组转化为字符串后,字符串的长度   1653
为什么每次字符串长度都变短了,我用其他流方式也会遇到这个问题????