readline java怎么写,java中readline()方法参数是怎样的?

java中readline()方法参数是怎样的?

mip版  关注:156  答案:4  悬赏:10

解决时间 2021-01-24 16:46

343e44338304c60980f2fa3ae3147708.png

已解决

2021-01-24 10:26

static int BUFSIZE = 1024 * 8;byte[] buffs = new byte[BUFSIZE * 8];ServletInputStream sis = request.getInputStream();int rtnPos = 0;rtnPos = sis.readLine(buffs, 0, buffs.length);

最佳答案

8e80eb331c98c0cda4b2c2ca0259a4db.png

2021-01-24 10:55

java中readLine()是没有参数的。

具体用法如下:

public static void readFileByLines(String fileName) {

File file = new File(fileName);

BufferedReader reader = null;

try {

System.out.println("以行为单位读取文件内容,一次读一行");

reader = new BufferedReader(new FileReader(file));

String tempString = null;

int line = 1;

//一次读一行,读入null时文件结束

while ((tempString = reader.readLine()) != null) {

//把当前行号显示出来

System.out.println("line " + line + ": " + tempString);

line++;

}

reader.close();

} catch (IOException e) {

e.printStackTrace();

} finally {

if (reader != null) {

try {

reader.close();

} catch (IOException e1) {

}

}

}

}

全部回答

54a3895d6a54de061aafbd0222c33c8a.png

1楼

2021-01-24 12:21

package com.zy.test;

import java.io.BufferedReader;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

public class Test {

public static void main(String args[]){

try {

FileReader fr = new FileReader("D:/www/a.txt");

BufferedReader br = new BufferedReader(fr);

String content = null;

while((content = br.readLine())!=null){

System.out.println(content);

}

br.close();

fr.close();

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

}

a0fb4d8e19efb283482206c643f1702f.png

2楼

2021-01-24 12:00

static int BUFSIZE = 1024 * 8;

byte[] buffs = new byte[BUFSIZE * 8];

ServletInputStream sis = request.getInputStream();

int rtnPos = 0;

rtnPos = sis.readLine(buffs, 0, buffs.length);

这个你看不明白?

buffs就是byte[] buffs = new byte[BUFSIZE * 8]; byte的数组,0是起始位置,buffs.length应该是偏移量!

15f789f29347de404f79f17e154178ca.png

3楼

2021-01-24 11:07

readLine 只有Console类下一个方法带参数,其他的都不带参数。

public String readLine(String fmt,

Object... args)提供一个格式化提示,然后从控制台读取单行文本。

参数:

fmt - 格式字符串语法中描述的格式字符串。

args - 格式字符串中的格式说明符引用的参数。如果参数多于格式说明符,则忽略额外的参数。参数的最大数量受到 Java 虚拟机规范定义的 Java 数组最大维数的限制。

返回:

包含从控制台读取的行的字符串,该字符串不包含任何行终止符;如果已到达流的末尾,则返回 null。

你自己查API文档啊,这是最好的JAVA资料

我要举报

如果感觉以上信息为低俗/不良/侵权的信息,可以点下面链接进行举报,我们会做出相应处理,感谢你的支持!

点此我要举报以上信息!

推荐资讯

大家都在看

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值