nus-cs2113-AY2122S2 / forum

3 stars 2 forks source link

Creating File #36

Open FaliciaOng opened 2 years ago

FaliciaOng commented 2 years ago

When creating the file, do we have to manually create the file "data"? I tried to run the code given in the textbook but i was not able to generate the data.txt file. After some googling, I could only make it work after calling f.getParentFile().mkdirs() and then f.createNewFile(). Is this way of creating the file acceptable?

image

okkhoy commented 2 years ago

The new File() in the code snippet is only creating the file object to handle the file fruits.txt in the data folder. See the explanation just above the code snippet image

I could only make it work after calling f.getParentFile().mkdirs() and then f.createNewFile(). Is this way of creating the file acceptable?

If your intention is to create a file programmatically, this is one way to do it, and acceptable.

FaliciaOng commented 2 years ago

Thank you for the clarification, for week 6 IP, I would like to confirm with you that we are expected to create the file at startup, save the contents when updated, load to file the when programs run again and handle 2 exceptions(when the file does not exist and when a folder does not exist)?

okkhoy commented 2 years ago

image 👆 is this what you are asking? If so, yes