Advertisement
1) PrintStream(File file) |
---|
This constructor creates a PrintStream object to write data to a file specified by the File object. Example-:
|
2) PrintStream(OutputStream os) |
---|
This constructor takes an OutputStream object in the parameters to write data to this output stream.
Example-:
|
Methods | Description |
---|---|
flush() | This method flushes any buffered data to be written out of this output stream. |
write() | This method writes one byte at a time to this output stream. |
write(byte[]) | This method writes a whole byte array at a time to this output stream. |
print(char c) | This method prints a character(primitive data type) to this output stream. print() methods don't add a newline character. |
print(int i) | This method prints an int(primitive data type). |
print(long l) | This method prints a long(primitive data type). |
print(float f) | This method writes a float (primitive data type) |
print(double d) | This method writes a double (primitive data type). |
print(boolean b) | This method writes a boolean(primitive data type). |
println(char c) | This method prints a character(primitive data type) to this output stream. println() methods add a newline character. |
println(int i) | This method prints an int(primitive data type). |
println(long l) | This method prints a long(primitive data type). |
println(float f) | This method writes a float (primitive data type). |
println(double d) | This method writes a double (primitive data type). |
println(boolean b) | This method writes a boolean(primitive data type). |
println(Object o) | This method writes an Object. |
close() | This method closes this output stream and also frees any resources connected with this output stream. |
Advertisement
import java.io.*;
class A
{
public String toString()
{
return "-An object is created-" ;
}
public static void main(String... ar)
{
A ob= new A();
try
{
FileOutputStream fos= new FileOutputStream("D://TextBook.txt");
PrintStream ps= new PrintStream(fos);
ps.println(1985);
ps.print('C');
ps.println(23.45f);
ps.println("Java Rules");
ps.println(ob);
ps.flush();
ps.close();
fos.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}
Advertisement
Advertisement
Please check our latest addition
C#, PYTHON and DJANGO
Advertisement