public static void printBBB(File myFile) throws IOException{ FileInputStream myFileInputStream = new FileInputStream(myFile); //添加部分 FileOutputStream myOutputStream = new FileOutputStream("e:\\b.mp3"); byte[] myByte = new byte[1024*1024]; int j=0; int len=0; System.out.println(myFile.length()); long startTime=System.currentTimeMillis(); while( (len = myFileInputStream.read(myByte, 0, myByte.length))!=-1){ for (int i = 0; i < len; i++) { if(j++%73 == 0){ System.out.println("\r\n"+"10个数据"); } System.out.print(Integer.toHexString(myByte[i]&0xff)+" "); /*********************************** 添加一下代码后打印输出的数据乱码,第一行数据,正常,然后一大片 00 ,后面又是乱码 ************************************/ myOutputStream.write(myByte,0,len); myOutputStream.flush(); } long endTime=System.currentTimeMillis(); System.out.println("\r\n"+"读取文件所用时间:"+((endTime - startTime)/1000)); } myFileInputStream.close(); myOutputStream.close(); }
看看你的项目默认的字符编码和你的字符编码是否一致 不一致就会出现乱码问题