0
 try(ObjectOutPutStream utfil = new ObjectOutPutStream
               (new FileOutputStream("src/eierliste.data")))

Does this instruction create the file for me, or do I have to manually create the file? Where is src located? Which folder? What does that mean: "src/eierliste.data"

MikeD
  • 8,763
  • 2
  • 25
  • 49

2 Answers2

1

This is a new syntax present since Java 7, it's called try-with-resources. It's a shortcut to ensure that the resource opened within the try is closed automatically when the block ends, what you'd normally do in a finally block. Quoting the tutorial, this:

try (BufferedReader br = new BufferedReader(new FileReader(path))) {
    return br.readLine();
}

… is equivalent to this:

BufferedReader br = new BufferedReader(new FileReader(path));
try {
    return br.readLine();
} finally {
    if (br != null)
        br.close();
}

Now regarding the code in the question: it's creating a new file only if it didn't exist before (see this answer), and it's opening an ObjectOutPutStream for writing to it.

Community
  • 1
  • 1
Óscar López
  • 215,818
  • 33
  • 288
  • 367
1

this video is super helpful as it also has futher tutorials that show how to read and edit

http://www.youtube.com/watch?v=G0DfmD0KKyc