file I/O
unknown
java
a year ago
982 B
6
Indexable
File file = new File("fateh.txt");
try {
if (!file.exists()) {
file.createNewFile();
System.out.println("file created");
}
} catch (IOException e) {
e.printStackTrace();
e.getCause();
System.out.println(e.getMessage());
}
try {
Writer writer = new FileWriter(new File("fateh.txt"), false);
writer.write("fateh is good person \n fateh is bad person asdfasdf \n second test");
writer.flush();
writer.close();
} catch (IOException e) {
System.out.println(e.getMessage());
}
try {
Scanner reader = new Scanner(file);
while (reader.hasNextLine()) {
System.out.println(reader.nextLine());
}
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
}
Editor is loading...
Leave a Comment