1. If directory in which the file should be created does not exist, method createNewFile() throws IOException.
try {
File f = new File("test", "test.txt");
f.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
----------------------------------------------------------------------------------------------------------
2. Method renameTo accepts only File objects not String!
Prototype of the method:
public boolean renameTo(File dest)
----------------------------------------------------------------------------------------------------------
3. If there is no directory structure, PrintWriter throws FileNotFoundException.
try {
PrintWriter pw = new PrintWriter("test/test/test.xml");
}catch(FileNotFoundException e) {
e.printStackTrace();
}
when the directory structure exists, the physical file is created by PrintWriter
try {
PrintWriter pw = new PrintWriter("test.xml");
}catch(FileNotFoundException e) {
e.printStackTrace();
}
----------------------------------------------------------------------------------------------------------
4. flush() method is only available in writers: FileWriter, BufferedFileWriter, PrintWriter.
flush() method is not available in readers.
Brak komentarzy:
Prześlij komentarz