Hi guys, I have a problem.
Im trying to read from a file which contains
one, two, three, four.
The output I get is
one
two
three
four
But I want to make it read every other line.
one
three
etc.
How would I go about that?
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class FileSkipLine
{
public static void main( String strarrArgs[] )
{
File myFile;
Scanner myScanner;
boolean bContinue;
String strLine;
try
{
myFile = new File( "C:\\temp\\data.txt" );
myScanner = new Scanner( myFile );
bContinue = myScanner.hasNext( );
while( bContinue == true )
{
strLine = myScanner.nextLine( );
System.out.println( strLine );
bContinue = myScanner.hasNext( );
}
}
catch( FileNotFoundException exp )
{
System.out.println( " didn't find the file, does it exist? is the location correct? ");
}
catch( Exception exp )
{
System.out.println( " an exception happened, here is the message " + exp.getMessage( ) );
exp.printStackTrace( );
} } }