刚刚开始使用Java进行编程。如果我有一个数组如下存储在一个.txt文件:将数组的字符串表示形式转换回java中的int数组
[10, 22, 30, 55, 10, 20, 19]
如何将其转换回一个正常的INT []数组要在代码中使用?
我需要能够将它直接存储在这样的txt文件中,以便我可以手动对其进行更改。我用BufferedReader读取数组。我怎样才能把读数组放入一个int []数组?
int[] field;
try {
String line;
br = new BufferedReader(new FileReader(gameFilePath));
while((line = br.readLine()) != null) { // Read the first line and assume it is the stored array
field = line;
System.out.println("-------------------------------------------------------------------");
System.out.println(line);
}
} catch(IOException e) {
e.printStackTrace();
}
你尝试过什么? –
转换它?您可能想要阅读文件的内容。 – ChiefTwoPencils
我已经尝试了ObjectOutputStream和ObjectInputStream,但是这些序列化数组数据 – Josh