-1
我想填充一個數組而不知道它的大小。我用ArrayList來做到這一點NumberFormatException當填充ArrayList
String filename = "C:\\tmTest.123";
int tmHex;
FileInputStream in = null;
ArrayList<Byte> bytes = new ArrayList<Byte>();
try
{
in = new FileInputStream(filename);
while((tmHex = in.read()) != -1)
{
bytes.add(Byte.parseByte("", tmHex));
}
}
catch (IOException ex)
{
Logger.getLogger(NARSS02.class.getName()).log(Level.SEVERE, null, ex);
}
但我得到了一個異常NumberFormatException。爲什麼? 以及在從文件中讀取字節期間是否有其他方法來填充陣列。
'「」'不是有效的數字字符串。 –
您應該使用'List bytes = new ArrayList ();',因爲'ArrayList'是'List'的實現 - 與具體問題無關。 –
Lion