-2

如下修改 MP3 文件会导致内存不足错误。无论如何我可以更有效地执行以下操作(即使用更少的内存)

public void BacaMP3(){
    String a = System.getProperty("user.dir") + "/src/MP3/21.waltz-cut.mp3";
 String bitMP3="";
    try {
         File song = new File(a);
         FileInputStream file = new FileInputStream(song);

         int  input = 0;
         System.out.println("Creating file ...");
         while (input != -1) {
             input = file.read();
             count++;
             if (input==-1)bitMP3="#";
             else{
                 bitMP3 = Integer.toBinaryString(input);
                 while(bitMP3.length()<8){
                    bitMP3="0"+bitMP3;
                 }
             }

             area1.append(bitMP3+"\n");

         }
         System.out.println(count);
         file.close();

         System.out.println("Done");
     } catch (Exception e) {
         System.out.println("Error  " + e.toString());
     }
}
4

1 回答 1

0

作为首发

while(bitMP3.length()<8){
    bitMP3="0"+bitMP3; // Here you are creating two string till count is less than 8 move it to string buffer
}

area1.append(bitMP3+"\n"); // Here you are already using string buffer why doing string concatenation then change to area1.append(bitMP3).append("\n");
于 2012-05-16T14:08:41.463 回答