-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWrite_File.java
More file actions
40 lines (31 loc) · 848 Bytes
/
Write_File.java
File metadata and controls
40 lines (31 loc) · 848 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
37
38
39
40
package Exp10;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Write_File {
public static void main(String[] args) {
try {
FileOutputStream fos=new FileOutputStream("D:/myprofile/MyFile.txt");
String msg="Welcome to Java Class";
byte b[]=msg.getBytes();
FileInputStream fis=new FileInputStream("D:/myprofile/MyFile.txt");
//Method1
//for(byte x:b)
// fos.write(x);
//Method 2
fos.write(b);
//Method 3
// fos.write(b,11,msg.length()-11);
int x;
while((x=fis.read())!=-1) {
System.out.print((char)x);
}
fos.close();
} catch (FileNotFoundException e) {
System.out.println(e);
}catch (IOException e) {
System.out.println(e);
}
}
}