codecamp

鸿蒙OS StringWriter

StringWriter

java.lang.Object

|---java.io.Writer

|---|---java.io.StringWriter

public class StringWriter
extends Writer

在字符串缓冲区中收集其输出的字符流,然后可用于构造字符串。

关闭 StringWriter 无效。 可以在流关闭后调用此类中的方法,而不会生成 IOException。

Since:

JDK1.1

字段摘要

从类 java.io.Writer 继承的字段
lock

构造函数摘要

构造函数 描述
StringWriter() 使用默认的初始字符串缓冲区大小创建一个新的字符串编写器。
StringWriter(int initialSize) 使用指定的初始字符串缓冲区大小创建一个新的字符串编写器。

方法总结

修饰符和类型 方法 描述
StringWriter append(char c) 将指定的字符附加到这个 writer。
StringWriter append(CharSequence csq) 将指定的字符序列附加到此编写器。
StringWriter append(CharSequence csq, int start, int end) 将指定字符序列的子序列附加到此编写器。
void close() 关闭 StringWriter 无效。
void flush() 冲洗流。
StringBuffer getBuffer() 返回字符串缓冲区本身。
String toString() 将缓冲区的当前值作为字符串返回。
void write(char[] cbuf, int off, int len) 写入字符数组的一部分。
void write(int c) 写一个字符。
void write(String str) 写一个字符串。
void write(String str, int off, int len) 写一个字符串的一部分。
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
从类 java.io.Writer 继承的方法
write

构造函数详细信息

StringWriter

public StringWriter()

使用默认的初始字符串缓冲区大小创建一个新的字符串编写器。

StringWriter

public StringWriter(int initialSize)

使用指定的初始字符串缓冲区大小创建一个新的字符串编写器。

参数:

参数名称 参数描述
initialSize 在自动扩展之前将适合此缓冲区的 char 值的数量

Throws:

Throw名称 Throw描述
IllegalArgumentException 如果 initialSize 为负数

方法详情

write

public void write(int c)

写一个字符。

覆盖:

在 Writer 类中写

参数:

参数名称 参数描述
c int 指定要写入的字符

write

public void write(char[] cbuf, int off, int len)

写入字符数组的一部分。

指定者:

在 Writer 类中写

参数:

参数名称 参数描述
cbuf 字符数组
off 开始写入字符的偏移量
len 要写入的字符数

write

public void write(String str)

写一个字符串。

覆盖:

在 Writer 类中写

参数:

参数名称 参数描述
str 要写入的字符串

write

public void write(String str, int off, int len)

写一个字符串的一部分。

覆盖:

在 Writer 类中写

参数:

参数名称 参数描述
str 要写入的字符串
off 开始写入字符的偏移量
len 要写入的字符数

append

public StringWriter append(CharSequence csq)

将指定的字符序列附加到此编写器。

形式为 out.append(csq) 的此方法的调用与调用的行为方式完全相同

     out.write(csq.toString()) 

根据字符序列 csq 的 toString 规范,可能不会附加整个序列。 例如,调用字符缓冲区的 toString 方法将返回一个子序列,其内容取决于缓冲区的位置和限制。

指定者:

在接口 Appendable 中追加

覆盖:

追加到类 Writer

参数:

参数名称 参数描述
csq 要追加的字符序列。 如果 csq 为空,则将四个字符“null”附加到此编写器。

返回:

This writer

Since:

1.5

append

public StringWriter append(CharSequence csq, int start, int end)

将指定字符序列的子序列附加到此编写器。

当 csq 不为空时,以 out.append(csq, start, end) 形式调用此方法的行为与调用完全相同

     out.write(csq.subSequence(start, end).toString()) 

指定者:

在接口 Appendable 中追加

覆盖:

追加到类 Writer

参数:

参数名称 参数描述
csq 从中追加子序列的字符序列。 如果 csq 为 null,则将附加字符,就好像 csq 包含四个字符“null”。
start 子序列中第一个字符的索引
end 子序列中最后一个字符之后的字符的索引

返回:

This writer

Throws:

Throw名称 Throw描述
IndexOutOfBoundsException 如果 start 或 end 为负数,则 start 大于 end,或者 end 大于 csq.length()

Since:

1.5

append

public StringWriter append(char c)

将指定的字符附加到这个 writer。

以 out.append(c) 形式调用此方法的行为与调用完全相同

     out.write(c) 

指定者:

在接口 Appendable 中追加

覆盖:

追加到类 Writer

参数:

参数名称 参数描述
c 要附加的 16 位字符

返回:

This writer

Since:

1.5

toString

public String toString()

将缓冲区的当前值作为字符串返回。

覆盖:

类 Object 中的 toString

返回:

对象的字符串表示形式。

getBuffer

public StringBuffer getBuffer()

返回字符串缓冲区本身。

返回:

StringBuffer 保存当前缓冲区值。

flush

public void flush()

冲洗流。

指定者:

在接口 Flushable 中刷新

指定者:

在 Writer 类中刷新

close

public void close() throws IOException

关闭 StringWriter 无效。 可以在流关闭后调用此类中的方法,而不会生成 IOException。

指定者:

在接口 AutoCloseable 中关闭

指定者:

在接口Closeable中关闭

指定者:

close in class Writer

Throws:

Throw名称 Throw描述
IOException 如果发生 I/O 错误
鸿蒙OS StringReader
鸿蒙OS Writer
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

鸿蒙OS 开发

鸿蒙OS 术语

鸿蒙OS Java API参考

鸿蒙OS ohos.aafwk.ability

鸿蒙OS ohos.aafwk.abilityjet.activedata

鸿蒙OS ohos.aafwk.content

鸿蒙OS java.lang

鸿蒙OS java.Util

鸿蒙OS java.Util class

鸿蒙OS ohos.data.dataability

鸿蒙OS ohos.data.dataability class

鸿蒙OS ohos.agp.components

鸿蒙OS ohos.agp.components interface

鸿蒙OS ohos.agp.components class

鸿蒙OS ohos.global.configuration

鸿蒙OS java.io

鸿蒙OS ohos.data.resultset

鸿蒙OS ohos.data.resultset interface

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }