作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
private static int readAndWriteInputStream( final InputStream is, final OutputStream outStream ) throws IOException {
final byte[] buf = new byte[ 8192 ];
int read = 0;
int cntRead;
while ( ( cntRead = is.read( buf, 0, buf.length ) ) >=0 )
{
outStream.write(buf, 0, cntRead);
read += cntRead;
}
outStream.write("\n".getBytes());
return read;
}
outStream.write(buf, 0, cntRead) 之前;我想将每一行(从输入文本读取)文件放入字符串中。是否可以将此字节数据放入字符串中。
最佳答案
更好的方法是使用 proper String constructor :
String s = new String(buf, 0, cntRead);
这样可以避免不必要的数组复制。
此外,如果数据编码可能与您平台的默认编码不同,您必须使用 a constructor它采用 Charset
作为附加参数。
关于java - 获取字符串中的bytedata数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29350079/
我正在使用 Flutter 将“ Assets ”加载到文件中,以便 native 应用程序可以访问它。 这是我加载资源的方式: final dbBytes = await rootBundle.lo
multi_image_picker: 2.4.11插件返回 List , 每个 Asset有一个 imageData ByteData 属性. 如何在 Flutter 中显示这些内容? 最佳答案 您
我正在读取一个二进制文件并想将其转换为字符串。我如何在 Dart 中做到这一点? 最佳答案 试试下面的 String getStringFromBytes(ByteData data) { fin
我是这样做的: Pointer _byteDataToPointer(ByteData byteData) { final uint8List = byteData.buffer.asUint8L
我是一名优秀的程序员,十分优秀!