Browse Source

Checking whether file exists and decide whether to append or create a new file.

Christophe Debruyne 7 years ago
parent
commit
e952f18440
1 changed files with 4 additions and 1 deletions
  1. 4 1
      src/r2rml/Main.java

+ 4 - 1
src/r2rml/Main.java

@@ -116,7 +116,10 @@ public class Main {
 		// Make sure that we write output as UTF-8 as windows machines
 		// use a different encoding for the writers...		
 		Path path = Paths.get(file.getPath());
-		BufferedWriter bw = Files.newBufferedWriter(path, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
+		
+		if(!file.exists()) file.createNewFile();
+		
+		BufferedWriter bw = Files.newBufferedWriter(path, StandardCharsets.UTF_8, append ? StandardOpenOption.APPEND : StandardOpenOption.TRUNCATE_EXISTING);
 		model.write(bw, format);
 		bw.close();
 	}