يضيف PrintStream وظيفة إلى دفق إخراج آخر، وهو القدرة على طباعة تمثيلات لقيم البيانات المختلفة بشكل ملائم. على عكس تدفقات الإخراج الأخرى، لا يقوم PrintStream مطلقًا بطرح IOException؛ بدلاً من ذلك، تقوم المواقف الاستثنائية فقط بتعيين إشارة داخلية يمكن اختبارها عبر التابع checkError. اختياريًا، يمكن إنشاء PrintStream بحيث يتم التدفق تلقائيًا. يتم تحويل كافة الأحرف المطبوعة بواسطة PrintStream إلى بايتات باستخدام ترميز الأحرف الافتراضي للنظام الأساسي. يجب استخدام فئة PrintWriter في المواقف التي تتطلب كتابة الأحرف بدلاً من البايتات. إعلان الطبقة
public class PrintStream extends FilterOutputStream implements Appendable Closeable
مجال
protected OutputStream out:This is the output stream to be filtered.
البنائين والوصف
برينتستريم (ملف ملف):
يقوم بإنشاء دفق طباعة جديد دون مسح الخط تلقائيًا بالملف المحدد.
PrintStream (سلسلة ملف csn):
ينشئ دفق طباعة جديدًا دون مسح الخط تلقائيًا بالملف المحدد ومجموعة الأحرف.
PrintStream (إخراج الإخراج):
إنشاء دفق طباعة جديد.
PrintStream (إخراج OutputStream من التدفق التلقائي المنطقي):
إنشاء دفق طباعة جديد.
PrintStream (OutputStream خارج ترميز سلسلة التدفق التلقائي المنطقي)
: إنشاء دفق طباعة جديد.
PrintStream (اسم ملف السلسلة):
يقوم بإنشاء دفق طباعة جديد دون مسح الخط تلقائيًا باسم الملف المحدد.
PrintStream (سلسلة اسم الملف، سلسلة CSN):
يقوم بإنشاء دفق طباعة جديد دون مسح السطر تلقائيًا باسم الملف المحدد ومجموعة الأحرف. طُرق:
إلحاق PrintStream (شار ج):
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 (CharSequence csq int start int end):
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 (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
خطأ منطقي منطقي ():
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
خطأ محمي واضح () :
Clears the internal error state of this stream.
Syntax : protected void clearError()
إغلاق باطل () :
Closes the stream.
Syntax : public void close() Overrides: close in class FilterOutputStream
تدفق الفراغ ():
Flushes the stream.
Syntax : public void flush() Overrides: flush in class FilterOutputStream
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
تنسيق PrintStream (كائن تنسيق السلسلة... الحجج):
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
طباعة باطلة (منطقية ب):
Prints a boolean value.
Syntax : public void print(boolean b)
طباعة باطلة (شار ج):
Prints a character.
Syntax : public void print(char c)
طباعة باطلة (شار [] ق):
Prints an array of characters.
Syntax : public void print(char[] s)
طباعة باطلة (د مزدوج):
Prints a double-precision floating-point number.
Syntax : public void print(double b)
طباعة باطلة (تعويم f):
Prints a floating-point number.
Syntax : public void print(float f)
طباعة باطلة (int i):
Prints an integer.
Syntax : public void print(int i)
طباعة باطلة (طويلة):
Prints a long integer.
Syntax : public void print(long l)
طباعة باطلة (كائن كائن):
Prints an object.
Syntax : public void print(Object obj)
طباعة باطلة (سلسلة):
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. الإخراج:
true14.533GeeksforGeeks java.io.FileOutputStream@1540e19dGeek false Welcome to my First program
المقالة التالية: Java.io.Printstream فئة في جافا | مجموعة 2 إنشاء اختبار