2D配列の入力を.txt
ファイルに保存する方法があります。ただし、通常は過去のプロジェクトで追加できるように、の最後にtrueを付けてもFileWriter fw = new FileWriter("CBB.dat");
、ファイルは次のエントリで上書きする前に1つのエントリしか受信しません。これはどのように修正されますか?
public void Save(String[][] EntryList)
{
try
{
File file = new File("CBB.dat");
// if file doesnt exists, then create it
if (!file.exists())
{
file.createNewFile();
}
if (EntryList[0][0] != null)
{
DataOutputStream outstream;
outstream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));
for (int row = 0; row < EntryList.length; row++)
{
for (int col = 0; col < EntryList[row].length; col++)
{
if (EntryList[row][col] != null) outstream.writeUTF(EntryList[row][col]);
}
outstream.close();
}
}
else System.out.print("Something is wrong");
} catch (IOException e)
{
e.printStackTrace();
}
}