Java中CharArrayWriter类的writeTo(Writer)方法用于将CharArrayWriter的内容写入另一个字符流。
public void writeTo(Writer out) throws IOException
参数:此方法接受一个代表输出流的参数,该输出流是目标流。返回值:此方法不返回任何值。异常:如果发生I /O错误,此方法将引发IOException。下面的程序演示了writeTo(Writer)方法在IO包的CharArrayWriter类中:程序1:
Java
// Java program to illustrate
// CharArrayWriter writeTo(Writer) method
import java.io.*;
public class GFG {
public static void main(String[] args)
throws IOException
{
// Create charArrayWriter
CharArrayWriter charArrayWriter
= new CharArrayWriter();
String str = "GEEKS";
charArrayWriter.write(str);
// Create outputStream
CharArrayWriter out
= new CharArrayWriter();
charArrayWriter.writeTo(out);
// print the outputStream
System.out.println(
out.toString());
}
}
输出:
GEEKS
程序2:
Java
// Java program to illustrate
// CharArrayWriter writeTo(Writer) method
import java.io.*;
public class GFG {
public static void main(String[] args)
throws IOException
{
// Create charArrayWriter
CharArrayWriter charArrayWriter
= new CharArrayWriter();
charArrayWriter.write("GEEKSFORGEEKS");
// Create outputStream
CharArrayWriter out
= new CharArrayWriter();
charArrayWriter.writeTo(out);
// print the outputStream
System.out.println(
out.toString());
}
}
输出:
GEEKSFORGEEKS
参考文献:
https://docs.oracle.com/javase/10/docs/api/java/io/CharArrayWriter.html#writeTo(java.io.Writer)
相关用法
- Java ByteArrayOutputStream writeTo()用法及代码示例
- Java CharArrayWriter write()用法及代码示例
- Java CharArrayWriter close()用法及代码示例
- Java CharArrayWriter append()用法及代码示例
- Java CharArrayWriter toString()用法及代码示例
- Java CharArrayWriter toCharArray()用法及代码示例
- Java CharArrayWriter reset()用法及代码示例
- Java CharArrayWriter size()用法及代码示例
- Java CharArrayWriter flush()用法及代码示例
- Java Java lang.Long.byteValue()用法及代码示例
- Java Java lang.Long.highestOneBit()用法及代码示例
- Java Java lang.Long.numberOfLeadingZeros()用法及代码示例
- Java Java.util.Collections.rotate()用法及代码示例
- Java Java lang.Long.lowestOneBit()用法及代码示例
- Java Java lang.Long.numberOfTrailingZeros()用法及代码示例
- Java Java.util.Collections.disjoint()用法及代码示例
- Java Java lang.Long.reverse()用法及代码示例
注:本文由纯净天空筛选整理自pp_pankaj大神的英文原创作品 CharArrayWriter writeTo() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。