-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