File tree Expand file tree Collapse file tree 4 files changed +81
-0
lines changed
java/com/javaprogramto/files/printwriter/tofile Expand file tree Collapse file tree 4 files changed +81
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .javaprogramto .files .printwriter .tofile ;
2+
3+ import java .io .File ;
4+ import java .io .FileNotFoundException ;
5+ import java .io .PrintWriter ;
6+
7+ public class PrintWriterToFileExample1 {
8+
9+ public static void main (String [] args ) throws FileNotFoundException {
10+
11+ File file = new File ("src/main/resources/print_writer/test2.txt" );
12+
13+ PrintWriter writer = new PrintWriter (file );
14+
15+ writer .println ("Line 1" );
16+ writer .println ("Line 2" );
17+ writer .println ("Line 3" );
18+
19+ writer .flush ();
20+
21+ writer .close ();
22+ System .out .println ("Done" );
23+
24+ }
25+
26+ }
Original file line number Diff line number Diff line change 1+ package com .javaprogramto .files .printwriter .tofile ;
2+
3+ import java .io .File ;
4+ import java .io .FileNotFoundException ;
5+ import java .io .PrintWriter ;
6+
7+ public class PrintWriterToFileExample2 {
8+
9+ public static void main (String [] args ) throws FileNotFoundException {
10+
11+ File file = new File ("src/main/resources/print_writer/file/test2.txt" );
12+
13+ PrintWriter writer = new PrintWriter (file );
14+
15+ writer .println ("Line 1" );
16+ writer .println ("Line 2" );
17+ writer .println ("Line 3" );
18+
19+ writer .flush ();
20+
21+ writer .close ();
22+ System .out .println ("Done" );
23+
24+ }
25+
26+ }
Original file line number Diff line number Diff line change 1+ package com .javaprogramto .files .printwriter .tofile ;
2+
3+ import java .io .File ;
4+ import java .io .FileNotFoundException ;
5+ import java .io .PrintWriter ;
6+
7+ public class PrintWriterToFileExample3 {
8+
9+ public static void main (String [] args ) throws FileNotFoundException {
10+
11+ File file = new File ("src/main/resources/print_writer/file/test2.txt" );
12+ file .getParentFile ().mkdirs ();
13+
14+ PrintWriter writer = new PrintWriter (file );
15+
16+ writer .println ("Line 1" );
17+ writer .println ("Line 2" );
18+ writer .println ("Line 3" );
19+
20+ writer .flush ();
21+
22+ writer .close ();
23+ System .out .println ("Done" );
24+
25+ }
26+ }
Original file line number Diff line number Diff line change 1+ Line 1
2+ Line 2
3+ Line 3
You can’t perform that action at this time.
0 commit comments