java.io.IOException:标记无效
问题描述:
public void createNewUser(String name, String passwort) {
try {
br = new BufferedReader(new FileReader("Data.txt"));
} catch (FileNotFoundException brCreateError) {
brCreateError.printStackTrace();
}
try {
br.mark(1);
System.out.println(br.readLine());
try {
if(br.readLine()==null) {
noUser=true;
}else {
noUser=false;
}
} catch (IOException e) {
e.printStackTrace();
}
br.reset();
} catch (IOException brMarkError) {
brMarkError.printStackTrace();
} ...
为什么在通过if语句后,markedChar值变为-2?java.io.IOException:标记无效
Thx为每个答案Nico。
答
public void mark(int readAheadLimit)
throws IOException
标记流中的当前位置。后续调用重置() 将尝试重新定位到此点的流。
...
参数:
readAheadLimit
- 对可能仍保留该标记可读取字符数量的限制。读取字符达到此限制或超出后尝试重置流 可能会失败。大于输入缓冲区大小的限制值 将导致分配大小不小于限制的新缓冲区 。因此应该小心使用较大的值 。
您将readAheadLimit
设置为1个字符,然后读取整行。这使得商标无效。
什么是br?什么是'markedChar'? –
'markedChar'在哪里? –
请张贴周边环境,以便我们更好地了解变量。 – Milk