...
Code Block | ||||
---|---|---|---|---|
| ||||
public void openFile_ncecreateFile(String filename) throws FileNotFoundException{ OutputStream out = new FileOutputStream(filename); // Work with FILE } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
public void noAlter_ncecreateFile(String filename) throws FileNotFoundException{ OutputStream out = new FileOutputStream(filename, true); if (!new File(filename).createNewFile()) { // File cannot be created...handle error } else { OutputStream out = new FileOutputStream(filename); // Work with FILE } } |
...
Code Block | ||||
---|---|---|---|---|
| ||||
public void createFile_cs(String filename) throws FileNotFoundException{
try (OutputStream out = new BufferedOutputStream(
Files.newOutputStream(Paths.get(filename),
StandardOpenOption.CREATE_NEW))) {
// Work with out
} catch (IOException x) {
// File not writable...handle error
}
} |
...