java - List<byte[]> fills wrong -
When the loop is over, the array in this code is filled with the same value everywhere. After some debugging I saw that the array on every add (fade) is completely filled with the same value.
list & lt; Byte [] & gt; Datas = new ArrayList & lt; Byte [] & gt; (); // CODE ... // FileInputStream fis = New FileInputStream (file); Byte [] Chef = new byte [2]; Int n; While ((n = fis.read (buff))! = - 1) {this.datas.add (fond); } Fis.close ();
I tried the same code with an array of string and it worked correctly ...
Why this is happening, and I How can i fix
You are filling ArrayList with similar examples of byte [] buffer variables so every time you Modify FoF (in fis.read (fond)) You are actually modifying all the items in ArrayList.
Try creating a new byte in each iteartion:
from the list & lt; Byte [] & gt; Datas = new ArrayList & lt; Byte [] & gt; (); // CODE ... // FileInputStream fis = New FileInputStream (file); Byte [] Chef = new byte [2]; Int n while ((n = fis.read (buff))! = - 1) {this.datas.add (fond); Buff = new byte [2]; } Fis.close ();
Comments
Post a Comment