跳过我的文件阅读器 [英] Skipping in my File Reader
本文介绍了跳过我的文件阅读器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public void file(){
String fileName = "hello.txt";
fileName = FileBrowser.chooseFile(true);
//Open a file and store the information into the OurList
try
{
String s = "";
File file = new File(fileName);
FileReader inputFile = new FileReader(file);
while( inputFile.read() != -1)
{
System.out.println(inputFile.read());
System.out.println();
}
}
catch(Exception exception)
{
System.out.println("Not a real file. List is already built");
}
}
所以我在这段代码上遇到了麻烦.我只想逐个字符地读取文件,但是现在它跳过了所有其他文件.我知道为什么它会跳过,在while循环中以及何时尝试打印它,但是据我所知,没有别的方法可以停止FileReader然后将它变成!=到-1.我该如何避免不跳过?
So i am having trouble with this piece of code. I want to just read in character by character from the file, but right now its skipping every other one. I know why its skipping, its in the while loop and when I try to print it, but as far as I can tell there isn't another way to stop FileReader then to make it != to -1. How can I get it to not skip?
推荐答案
int nextChar;
while( (nextChar = inputFile.read()) != -1)
{
System.out.println(nextChar);
System.out.println();
}
这篇关于跳过我的文件阅读器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文