-
Notifications
You must be signed in to change notification settings - Fork 394
Expand file tree
/
Copy pathPrintStreamDemo.java
More file actions
44 lines (33 loc) · 1.08 KB
/
PrintStreamDemo.java
File metadata and controls
44 lines (33 loc) · 1.08 KB
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
41
42
43
44
package printstreamdemo;
import java.io.*;
class Student
{
int rollno;
String name;
String dept;
}
public class PrintStreamDemo
{
/**
*
* @param args
* @throws Exception
* Student1.txt is a file upon that FileOutputStream is attached. And upon that PrintStream attach. So the 'ps' is an object of stream.
* So, whatever I write inside the stream object will go in the FileOutputStream and that will go into Student1.txt file.
*/
public static void main(String[] args) throws Exception
{
FileOutputStream fos=new FileOutputStream("C:\\MyJava\\Student1.txt");
PrintStream ps=new PrintStream(fos);
Student s=new Student();
s.rollno=10;
s.name="John";
s.dept="CSE";
// For write it in PrintStream. So, that it will go into the stu.txt file.
ps.println(s.rollno);
ps.println(s.name);
ps.println(s.dept); // OUTPUT -> Remember it has return three Strings [ 10, John, CSE ]
ps.close();
fos.close();
}
}