...
Skrive til fil:
Code Block |
---|
import java.io.FileNotFoundException; import java.io.PrintWriter; class WritingAFile { public static void main(String[] args) { try { PrintWriter outFile = new PrintWriter("test.txt"); outFile.println("hello world!"); outFile.close(); } catch (FileNotFoundException e) { System.err.println("Error: file 'test.txt' could not be opened for writing."); System.exit(1); } } } |