„PrintStream“ prideda funkcionalumą kitam išvesties srautui, ty galimybė patogiai spausdinti įvairių duomenų reikšmių atvaizdus. Skirtingai nuo kitų išvesties srautų, PrintStream niekada neatlieka IOException; Vietoj to išskirtinės situacijos tiesiog nustato vidinę vėliavėlę, kurią galima patikrinti naudojant checkError metodą. Pasirinktinai galima sukurti „PrintStream“, kad praplauti automatiškai. Visi „PrintStream“ atspausdinti simboliai konvertuojami į baitus, naudojant platformos numatytąją simbolių kodavimą. „PrintWriter“ klasė turėtų būti naudojama situacijose, kai reikia rašyti simbolius, o ne baitus. Klasės deklaracija
public class PrintStream extends FilterOutputStream implements Appendable Closeable
Laukas
protected OutputStream out:This is the output stream to be filtered.
Konstruktoriai ir aprašymas
PrintStream (failo failas):
Sukuria naują spausdinimo srautą be automatinio eilutės plovimo su nurodytu failu.
PrintStream (failo failo eilutė csn):
Sukuria naują spausdinimo srautą be automatinio eilutės plovimo su nurodytu failu ir simbolių rinkiniu.
PrintStream (OutputStream out):
Sukuria naują spausdinimo srautą.
PrintStream (OutputStream out loginis automatinis praplovimas):
Sukuria naują spausdinimo srautą.
PrintStream (OutputStream out loginis automatinis išsiliejimo eilutės kodavimas)
: sukuria naują spausdinimo srautą.
PrintStream (Eilutės failo pavadinimas) :
Sukuria naują spausdinimo srautą be automatinio eilutės plovimo nurodytu failo pavadinimu.
PrintStream (Eilutės failo pavadinimas String csn) :
Sukuria naują spausdinimo srautą be automatinio eilutės plovimo su nurodytu failo pavadinimu ir simbolių rinkiniu. Metodai:
„PrintStream“ priedas (char c) :
Appends the specified character to this output stream.
Syntax : public PrintStream append(char c) Parameters: c - The 16-bit character to append Returns: This output stream
PrintStream append (CharSequence csq int pradžia int pabaiga):
Appends the specified character sequence to this output stream.
Syntax : public PrintStream append(CharSequence csq int start int end) Parameters: csq - The character sequence from which a subsequence will be appended. start - The index of the first character in the subsequence end - The index of the character following the last character in the subsequence Returns: This output stream Throws: IndexOutOfBoundsException
„PrintStream“ priedas (CharSequence csq):
Appends a subsequence of the specified character sequence to this output stream.
Syntax : public PrintStream append(CharSequence csq) Parameters: csq - The character sequence to append. Returns: This output stream
loginio patikrinimo klaida ():
Flushes the stream and checks its error state.
Syntax : public boolean checkError() Returns: true if and only if this stream has encountered an IOException other than InterruptedIOException or the setError method has been invoked
Protected Void ClearError() :
Clears the internal error state of this stream.
Syntax : protected void clearError()
tuščias uždarymas () :
Closes the stream.
Syntax : public void close() Overrides: close in class FilterOutputStream
void flush ():
Flushes the stream.
Syntax : public void flush() Overrides: flush in class FilterOutputStream
PrintStream formatas (Locale l String format Object... args):
Writes a formatted string to this output stream using the specified format string and arguments.
Syntax : public PrintStream format(Locale l String format Object... args) Parameters: l - The locale to apply during formatting. If l is null then no localization is applied. format - A format string as described in Format string syntax args - Arguments referenced by the format specifiers in the format string. The number of arguments is variable and may be zero. Returns: This output stream Throws: IllegalFormatException NullPointerException
Writes a formatted string to this output stream using the specified format string and arguments.
Syntax : public PrintStream format(String format Object... args) Parameters : format - A format string as described in Format string syntax args - Arguments referenced by the format specifiers in the format string. The number of arguments is variable and may be zero. Returns: This output stream Throws: IllegalFormatException NullPointerException
negaliojantis spausdinimas (bulio reikšmė):
Prints a boolean value.
Syntax : public void print(boolean b)
tuščias spaudinys (c simbolis):
Prints a character.
Syntax : public void print(char c)
tuščias spaudinys (char[] s):
Prints an array of characters.
Syntax : public void print(char[] s)
tuščias spaudinys (dvigubas d):
Prints a double-precision floating-point number.
Syntax : public void print(double b)
tuščias spaudinys (plaukiojantis f):
Prints a floating-point number.
Syntax : public void print(float f)
tuščias spaudinys (int i):
Prints an integer.
Syntax : public void print(int i)
tuščias spaudinys (ilgas l):
Prints a long integer.
Syntax : public void print(long l)
tuščias spaudinys (Objekto objektas):
Prints an object.
Syntax : public void print(Object obj)
tuščias spaudinys (eilutės):
Prints a string.
Syntax : public void print(String s)
Java
importjava.io.FileNotFoundException;importjava.io.FileOutputStream;importjava.io.PrintStream;importjava.util.Locale;//Java program to demonstrate PrintStream methodsclassPrintstream{publicstaticvoidmain(Stringargs[])throwsFileNotFoundException{FileOutputStreamfout=newFileOutputStream('file.txt');//creating Printstream objPrintStreamout=newPrintStream(fout);Strings='First';//writing to file.txtcharc[]={'G''E''E''K'};//illustrating print(boolean b) methodout.print(true);//illustrating print(int i) methodout.print(1);//illustrating print(float f) methodout.print(4.533f);//illustrating print(String s) methodout.print('GeeksforGeeks');out.println();//illustrating print(Object Obj) methodout.print(fout);out.println();//illustrating append(CharSequence csq) methodout.append('Geek');out.println();//illustrating checkError() methodout.println(out.checkError());//illustrating format() methodout.format(Locale.UK'Welcome to my %s program's);//illustrating flush methodout.flush();//illustrating close methodout.close();}}
Note: The output might not be visible on online IDE as it is not able to read the file. Išvestis:
true14.533GeeksforGeeks java.io.FileOutputStream@1540e19dGeek false Welcome to my First program
Kitas straipsnis: Java.io.Printstream klasė Java | 2 rinkinys Sukurti viktoriną