Skip to content

Commit 5f9568e

Browse files
committed
Added Practice Demo Code5.
Signed-off-by: Someshdiwan <Someshdiwan369@gmail.com>
1 parent 12fd9b4 commit 5f9568e

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Living the Dreams
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import java.io.FileOutputStream;
2+
public class Demo5
3+
{
4+
public static void main(String args[])
5+
{
6+
try
7+
{
8+
FileOutputStream fout=new FileOutputStream("C:\\Users\\somes\\Downloads\\NoteApp\\JavaEvolution-Learning-Growing-Mastering\\Section23JavaIOStreams\\DemoCodes\\TXT Files\\Demo5.txt");
9+
String s="Living the Dreams";
10+
byte b[]=s.getBytes(); //converting string into byte array
11+
fout.write(b);
12+
fout.close();
13+
System.out.println("success");
14+
}
15+
catch(Exception e)
16+
{
17+
System.out.println(e);
18+
}
19+
}
20+
}
21+
/*
22+
getBytes --> Encodes this String into a sequence of bytes using the default charset, storing the result into a new byte array.
23+
24+
This program writes the full string "Welcome to JAVA" into a file named myFile.txt using FileOutputStream.
25+
The string is converted into a byte array using getBytes().
26+
The entire byte array is written to the file.
27+
Displays "success" when done.
28+
*/

0 commit comments

Comments
 (0)