
本文档主要讲述的是Android数据格式解析对象JSON用法;JSON可以将Java对象转成json格式的字符串,可以将json字符串转换成Java。比XML更轻量级,Json使用起来比较轻便和简单。JSON数据格式,在Android中被广泛运用于客户端和服务器通信,在网络数据传输与解析时非常方便。希望本文档会给有需要的朋友带来帮助;感兴趣的朋友可以过来看看
0
Since Java 9, the readNBytes() method can be added to the InputStream class. This method reads the requested number of bytes from an input stream into the given byte array. This method blocks until len bytes of input data have read, end of a stream is detected, or an exception is thrown. The readNBytes() method doesn't close an input stream. This method can be useful to avoid memory problems with large files.
<strong>public int readNBytes(byte[] b, int off, int len) throws IOException</strong>
在下面的示例中,我们在源文件夹中创建了一个名为“Technology.txt”的文件,其中包含简单的数据:{ "JAVA", "PYTHON", "JAVASCRIPT", "SELENIUM", "SCALA"}。
立即学习“Java免费学习笔记(深入)”;
import java.io.*;
import java.util.stream.*;
import java.nio.*;
import java.nio.file.*;
public class InputStreamReadNByteMethodTest {
InputStream inputStream = nputStreamReadNByteMethodTest.class.<strong>getResourceAsStream</strong>("Technology.txt");
public void testReadNBytes() throws Exception {
final byte[] data = new byte[10];
inputStream.<strong>readNBytes</strong>(data, 0, 7);
System.out.println(new String(data));
}
public static void main(String args[]) throws Exception {
InputStreamReadNByteMethodTest t = new InputStreamReadNByteMethodTest();
t.testReadNBytes();
}
}<strong>"JAVA",</strong>
以上就是在Java 9中何时使用InputStream的readNBytes()方法?的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号