-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileOutputStream.java
More file actions
36 lines (30 loc) · 1023 Bytes
/
FileOutputStream.java
File metadata and controls
36 lines (30 loc) · 1023 Bytes
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
29
30
31
32
33
34
35
36
package stream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Main {
public static void main(String[] args) {
try {
FileOutputStream file = new FileOutputStream("C:\\MyJava\\Data.txt");
String s = "Creating and writing into the text file.";
byte b[] = s.getBytes();
try {
file.write(s.getBytes());
// All bytes written at a time
/* for (byte x:b)
file.write(x); */
// One byte at a time by using loop
/* file.write(b, 5, s.length()-5); */
// writing some part of byte array
file.close();
}
catch (IOException exception){
System.err.println(exception);
}
}
catch (FileNotFoundException exception){
System.err.println(exception);
}
}
}