当我阅读文本文件时,如何跳过3行?以下仅显示第3行。我怎样才能纠正以下内容?
表值:
michelle
98765432
michelle@hotmail.com
22
3
6,7
代码:
try
{
String line = null;
while ((line = reader.readLine()) != null)
{
if (!(line.startsWith("*")))
{
//reader.readLine();
//reader.readLine();
//display booking IDs of target customer
if (line.equals(String.valueOf(customermobilenumber)))
{
System.out.println (reader.readLine());
}
}
}
}
答案 0 :(得分:0)
这似乎是一个愚蠢的解决方案,但我在更多的试验后得到它的工作&错误:
try
{
String line = null;
while ((line = reader.readLine()) != null)
{
if (!(line.startsWith("*")))
{
//display booking IDs of target customer
if (line.equals(String.valueOf(customermobilenumber)))
{
if (reader.readLine() != null )
{
//skip lines
reader.readLine();
reader.readLine();
System.out.println (reader.readLine());
}
}
}
}
}
答案 1 :(得分:0)
if (line.equals(String.valueOf(customermobilenumber)))
{
reader.readLine();
reader.readLine();
System.out.println (reader.readLine());
}
答案 2 :(得分:0)
try
{
String line = null;
while ((line = reader.readLine()) != null) // read first line
{
if (!(line.startsWith("*")))
{
String ph_no = reader.readLine(); // read next line (phone number)
String email = reader.readLine(); // read next line (email)
//display booking IDs of target customer
if (ph_no.equals(String.valueOf(customermobilenumber)))
{
// sysout(email);
sysout(reader.readLine());
sysout(reader.readLine());
sysout(reader.readLine());
}
}
}
}
答案 3 :(得分:-1)
while ((line = reader.readLine()) != null)
{
if (!(line.startsWith("*")))
{
//Skip line like this. just check after skip whether file ended or not! to avoid null pointer exception.
reader.readLine();
reader.readLine();
reader.readLine();
//display booking IDs of target customer
if (line.equals(String.valueOf(customermobilenumber)))
{
//use null pointer check here.
if(reader.readLine != null)
{
System.out.println (reader.readLine());
}
else
{
//File end.
}
}
}
}