File tree Expand file tree Collapse file tree
Section23JavaIOStreams/DemoCodes Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ Living the Dreams
Original file line number Diff line number Diff line change 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+ */
You can’t perform that action at this time.
0 commit comments