java - Exercice with scan files -


i have print lines of file "text", how can that?

public static void main(string[] args) throws filenotfoundexception{     file f =new file("text.txt");     scanner scanner = new scanner(f);      while(scanner.hasnextline()){         system.out.println(scanner.nextline());     } } 

thank you.

here easy way keep track of line on , how tell if number or not. if indeed number, print it.

public static void main(string[] args) throws filenotfoundexception {     file f = new file("text.txt");     scanner scanner = new scanner(f);     int counter = 1; //this tell line on      while(scanner.hasnextline()) {         if (counter % 2 == 0) { //this checks if line number             system.out.println(scanner.nextline());         }         counter++; //this says looked @ 1 more line     } } 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -