while ((len = bis.read(bys)) != -1) { System.out.print(new String(bys, 0, len)); String s2 = new String(bys, 0, len); score = Integer.valueOf(s2); }每个语句的含义
时间: 2023-06-20 11:06:08 浏览: 111
这段代码是从输入流 `bis` 中读取数据,并将读取到的字节存储到字节数组 `bys` 中。当读取到的字节数不为-1时,进入循环体,将字节数组中的内容转换为字符串并打印出来。然后将字节数组中的内容转换为字符串 `s2`,并将其转换为整数类型并赋值给变量 `score`。循环会一直执行直到读取完 `bis` 中的所有数据。
相关问题
int n = 0 ; while((n = reader.read()) != -1){ System.out.print((char)n);
这段代码使用 while 循环来读取文件中的数据,并将其以字符形式打印出来。循环中,`reader.read()` 方法会返回下一个字符的 ASCII 值,赋值给变量 n。如果读取到文件末尾,则 `reader.read()` 方法会返回 -1,循环结束。然后,使用 `(char)n` 将 ASCII 值转换为对应的字符,并使用 `System.out.print()` 方法打印出来。这样,文件中的内容就会被逐个字符地输出到控制台上。
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(String.valueOf(Text.class.getResourceAsStream("贪吃蛇游戏/null.txt")))); byte[] bys = new byte[1024]; int len; while ((len = bis.read(bys)) != -1) { System.out.print(new String(bys, 0, len));//测试用 String s2 = new String(bys, 0, len); score = Integer.valueOf(s2); }
这段代码的作用是从资源文件 "贪吃蛇游戏/null.txt" 读取数据,并将其中的整数值赋值给变量 score。具体来说,这段代码使用了 BufferedInputStream 类来读取文件,以 byte 数组的形式缓存了读取到的数据,然后将 byte 数组转换为字符串并解析其中的整数值,并将其赋值给 score 变量。需要注意的是,这段代码中的文件路径可能需要根据实际情况进行修改。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)