本文共 2020 字,大约阅读时间需要 6 分钟。
reset() method is available in java.io package.
reset()方法在java.io包中可用。
reset() method is used to reset this stream (CharArrayWriter) and it can re-use further without throwing away.
reset()方法用于重置此流(CharArrayWriter),并且可以进一步重用而不会丢弃。
reset() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
reset()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
reset() method does not throw an exception at the time of resetting the stream.
reset()方法在重置流时不会引发异常。
Syntax:
句法:
public void reset();
Parameter(s):
参数:
It does not accept any parameter.
它不接受任何参数。
Return value:
返回值:
The return type of the method is void, it returns nothing.
该方法的返回类型为void ,不返回任何内容。
Example:
例:
// Java program to demonstrate the example // of void reset() method of CharArrayWriterimport java.io.*;public class ResetOfCAW { public static void main(String[] args) { CharSequence cs = "Java World!!!"; CharArrayWriter caw = null; try { // Instantiates CharArrayWriter caw = new CharArrayWriter(); // By using append() method is to // append cs to the caw before calling // reset() caw.append(cs); // By using toString() method is // to represent the caw as a string System.out.print("caw: " + caw.toString()); System.out.println(); // By using reset() method isto reset the // caw stream caw.reset(); // Define CharSequence again cs = "Java Programming!!!!"; // By using append() method is to // append new cs to the caw after calling // reset() caw.append(cs); // By using toString() method is // to represent the caw as a string System.out.print("caw.reset(): " + caw.toString()); } catch (Exception ex) { System.out.println(ex.toString()); } finally { // Free all resources linked with this // stream if (caw != null) caw.close(); } }}
Output
输出量
caw: Java World!!!caw.reset(): Java Programming!!!!
翻译自:
转载地址:http://kvvzd.baihongyu.com/