Store 2D array (String) to file and retrieve it

后端 未结 3 683
广开言路
广开言路 2021-01-15 21:30

I have made a simple program that has a 2D String array storing lots of data. I have searched a lot of places for how to store and retrieve 2D arrays. I want to save the dat

3条回答
  •  一整个雨季
    2021-01-15 21:41

    You should be using FileOutputStream instead. FileWriter in character while ObjectOutputStream is binary output stream.

    public static void main(String[] args) {
        try {
            ObjectOutputStream toFile = new ObjectOutputStream(new FileOutputStream("//home//user//array.DATA"));
            toFile.writeObject(args);
            toFile.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    

提交回复
热议问题