gpt4 book ai didi

java - Java中从BufferReader读取字符字段

转载 作者:行者123 更新时间:2023-12-01 18:32:03 24 4
gpt4 key购买 nike

如何在java中读取字符字段中的一行字符?

private char[] w;
int i=0;

BufferedReader br = new BufferedReader(new FileReader("pathToFile..."));

char c = '-1';

while (c!='\n') {
w[i++] = (char) br.read();
}

我得到了java.lang.NullPointerException

最佳答案

试试这个

 private char[] w;

BufferedReader br = new BufferedReader(new FileReader("pathToFile..."));

String s = null;
// to iterate for each line in file
while ((s = br.readLine()) != null ) {
// this will store chars of line
w = s.toCharArray();
//TODO - do something based on w array

}

关于java - Java中从BufferReader读取字符字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23725822/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com