如题,
eg, 假设有个text文件或多个text文件,由于创建者的恶趣味等问题,格式不定,
a b c d
e f g h
i j k l
......
......
......
类似于如上格式,变量间有可能为>=1个的空格,或>=1个的TAB符分隔开
现在我想实现逐行的连续读入,赋值给几个变量。
我知道C++的大致实现方法,但是Java的尼玛不懂……
大致是
ifstream xxxStream;
while(xxxstream>>variable1>>variable2>>variable3>>variable4)
{
}
= =希望我表述的足够清楚。如果脑残了能很简单的实现,求教
------解决方案--------------------------------------------------------
- Java code
// 提前要准备好输入流 reader 。String temp = "";char nowChar = ' ';int nowCharInt = -1;while ((nowCharInt = reader.read()) != -1){ char nowChar = (char) reader.read(); if (nowChar == ' ' || nowChar == '\t') { if (temp.length() != 0) { // 这里说明已经完整读取了一个变量,请于此进行相关的操作。 } continue; } else { temp += nowChar; }}