-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWriteFiles.java
More file actions
28 lines (28 loc) · 1.2 KB
/
WriteFiles.java
File metadata and controls
28 lines (28 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.io.FileWriter;
import java.io.IOException;
import java.io.FileNotFoundException;
public class WriteFiles {
public static void main(String[]args)
{
//writing files in java to store ,share and reuse in future
//writing statement inside () in try block as per modern java
String textcontent= """
roses are red
violets are blue
BOOTY BOOTY BOOTY
ROCKIN' EVERYWHERE
""";
// by default the file gets saved in src folder
//you can define location of file by copying the location from properties of that folder and paste before text.txt (usee//)
try(FileWriter writer=new FileWriter("text.txt")){
writer.write(textcontent);
System.out.println("file has been written");
}
catch(FileNotFoundException e){
System.out.println("could not locate file location");
}
catch(IOException e){
System.out.println("could not write file");
}
}
}