-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathWriteFileDemo.java
More file actions
22 lines (19 loc) · 807 Bytes
/
WriteFileDemo.java
File metadata and controls
22 lines (19 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class WriteFileDemo {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
// Step -1 Create FileOutputStream And Specify the Path
// where u want to write the file
FileOutputStream fo = new FileOutputStream("/Users/amit/Documents/testing/test.txt");
// Step -2 Specify the Data to Write
String data= "hello this is sample data to store in a file";
// Step - 3 Convert Data into Bytes then write in a file
//fo.write(data.getBytes()); // write () store bytes in a file
fo.write("hello this is sample data to store in a file".getBytes());
// Step - 4 Close the File
fo.close();
System.out.println("Data Store in a File...");
}
}