How to open a .dat file in java program

后端 未结 5 1397
时光取名叫无心
时光取名叫无心 2020-12-10 19:09

I was handed some data in a file with an .dat extension. I need to read this data in a java program and build the data into some objects we defined. I tried the following, b

5条回答
  •  轮回少年
    2020-12-10 19:45

    A better way would be to use try-with-resources so that you would not have to worry about closing the resources.

    Here is the code.

        FileInputStream fis = new FileInputStream("news.dat");
        try(ObjectInputStream objectstream = new ObjectInputStream(fis)){
    
              objectstream.readObject();
        }
        catch(IOException e){
             //
        }
    

提交回复
热议问题