StringReader是Reader的继承类,从字面上就可看出,它是专门处理字符串的。 例:2.1.1 import java.io.*; public class TestMark_to_win { public static void main(String args[]) throws Exception { // /from multiline string to StringReader, then to console String s, s1 = new String(); s = "...
= -1) { // 处理读取的字符 char c = (char) data; System.out.print(c); data = reader.read(); } 复制代码 关闭StringReader对象。 reader.close(); 复制代码 完整的示例代码如下: import java.io.StringReader; public class Main { public static void main(String[] args) { String input = "H...
2.1 StringReader的用法 StringReader是Reader的继承类,从字面上就可看出,它是专门处理字符串的。 例:2.1.1 import java.io.*; public class TestMark_to_win { public static void main(String args[]) throws Exception { // /from multiline string to StringReader, then to console String s, s1 = new...
Stringstr="Hello, World!";Readerreader=newStringReader(str);// 将字符串转换为流 1. 2. 示例代码 下面是一个完整的示例代码,演示了如何将字符串转换为流并进行读取操作。 importjava.io.*;publicclassStringToStreamExample{publicstaticvoidmain(String[]args){Stringstr="Hello, World!";// 使用 ByteArray...
StringReader是装饰Reader的类,其用法是读取一个String字符串 package com.itbuluoge.test; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.StringReader; public class StringInputFile { ...
2、InputStream–>String inputStream input =null; StringBuffer out=newStringBuffer();byte[] b =newbyte[4096];for(intn; (n = input.read(b)) != -1;) { out.append(newString(b, 0, n)); }returnout.toString(); 3、Reader –>String ...
参考链接: Java Reader类 1、String –> InputStream InputStrem is = new ByteArrayInputStream(str.getBytes()); 或者 ByteArrayInputStream stream= new ByteArrayInputStream(str.getBytes()); 2、InputStream–>String inputStream input; StringBuffer out = new StringBuffer(); ...
Reader reader = null; BufferedReader r = new BufferedReader(reader); StringBuilder b = new StringBuilder(); String line; while((line=r.readLine())!=null) { b.append(line); b.append(“\r\n”); } return b.toString(); ——— 版权声明:本文为CSDN博主「Jay_...
Returns a string representation of the object. (Inherited from Object) TransferTo(Writer) Reads all characters from this reader and writes the characters to the given writer in the order that they are read. (Inherited from Reader) UnregisterFromRuntime() (Inherited from Object) Wait() ...
nullReader, read, read, transferTo クラス java.lang.Objectで宣言されたメソッド clone、equals、finalize、getClass、hashCode、notify、notifyAll、toString、wait、wait、waitコンストラクタの詳細 StringReader public StringReader(String s) 新しい文字列リーダーを作成します。 パラメータ: s - 文...