public class ScannerDemo {
   public static void main(String[] args) {

      String s = "Hello World! \n 3 + 3.0 = 6 ";

      // create a new scanner with the specified String Object
      Scanner scanner = new Scanner(s);

      // print the next line
      System.out.println("" + scanner.nextLine());

      // check if there is a next line again
      System.out.println("" + scanner.hasNextLine());

      // print the next line
      System.out.println("" + scanner.nextLine());

      // check if there is a next line again
      System.out.println("" + scanner.hasNextLine());

      // close the scanner
      scanner.close();
   }
}

        

public class GFG1 { 
    public static void main(String[] argv) 
        throws Exception 
    { 
  
        String s = "gfg 2 geeks!"; 
  
        // new scanner with the 
        // specified String Object 
        Scanner scanner = new Scanner(s); 
  
        // use US locale to interpret Lines in a string 
        scanner.useLocale(Locale.US); 
  
        // iterate till end 
        while (scanner.hasNextLine()) { 
  
            // print what is scanned 
            System.out.println(scanner.nextLine()); 
        } 
  
        // close the scanner 
        scanner.close(); 
    } 
} 

        

public class ScannerHasNextLine {

	public static void main(String[] args) throws FileNotFoundException {
		// Declare File object
		File file = new File("E:/tmp/java/tutorial/scanner/example.txt");
		// initialize the scanner
		Scanner scan = new Scanner(file);
		// iterate through the file line by line
		while(scan.hasNextLine()){
			// print the token
			System.out.println(scan.next());
		}
		scan.close();
	}
}

        

public class ScannerHasNextLineExample1 {    
    public static void main(String args[]){       
          String str = "Facebook.com \n 1 + 1 = 2.0 \n JavaTpoint.com ";  
        Scanner scanner = new Scanner(str);  
        //Print the next line  
        System.out.println(scanner.nextLine());  
        //Check if there is a next line again  
        System.out.println(scanner.hasNextLine());  
        System.out.println(scanner.nextLine());  
        //Check if there is a next line again  
        System.out.println(scanner.hasNextLine());  
        System.out.println(scanner.nextLine());  
        //Check if there is a next line again  
        System.out.println(scanner.hasNextLine());  
        scanner.close();  
      }    
}  

        

public class ScannerReadFile {
    public static void main(String[] args) {
        // Create an instance of File for data.txt file.
        File file = new File("data.txt");
        try {
            // Create a new Scanner object which will read the data
            // from the file passed in. To check if there are more 
            // line to read from it we check by calling the 
            // scanner.hasNextLine() method. We then read line one 
            // by one till all lines is read.
            Scanner scanner = new Scanner(file);
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                System.out.println(line);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}

        

public static void registerAllIPCams(String fname)
{
	File f = new File(fname);
	if(f.exists()&&f.isFile())
	{
		try {
			Scanner scan = new Scanner(f);
			while(scan.hasNextLine())
			{
				registerIPCam(scan.nextLine());
			}
			scan.close();
		} catch (FileNotFoundException e) {
		}
	}
}

        

public static void init() throws FileNotFoundException, IOException {

        Scanner scanner = new Scanner(file);
        scanner.nextLine(); //Skip the first (Title) line

        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            if (line.equals("*") || line.split(",").length < 3) { //To prevent reading the same line twice AND prevent reading a corrupted line
                break;
            }
            scores.put(Integer.parseInt(line.split(",")[1]), line.split(",")[0]); //Only looks at the first two columns (name and highscore)
        }

        sortScores();
        //printScores();
    }

        

private static void load(Language language, String string) throws Exception {
  Scanner scanner = new Scanner(string);
  while (scanner.hasNextLine()) {
    String line = scanner.nextLine();
    if (line.startsWith("#")) continue;
    int index = line.indexOf("=");
    if (index == -1) continue;
    String str = line.substring(0, index).toLowerCase();
    String localization = line.substring(index + 1);
    language.add(str, localization);
  }
  scanner.close();
}

        

public Map processFile() throws FileNotFoundException {
    //FileReader is used, not File, since File is not Closeable
    scanner = new Scanner(new FileReader(file));
    try {
        //Scanner to get each line
        while (scanner.hasNextLine()) {
            processLine(scanner.nextLine());
        }
    } finally {
        //Close the underlying stream
        scanner.close();
    }
    return map;
}

        

public boolean isVnrMapped() throws FileNotFoundException {
	
	try{
		  Thread.currentThread().sleep(500);
		}catch(InterruptedException ie){
		//If this thread was interrupted by another thread 
		}
	String filePath = MATLAB_PATH + MAPPING_PERFORMED + virtualNetReqNumber;
	fFile = new File(filePath);
	Scanner scanner = new Scanner(fFile);
	String[] decision;
	while (scanner.hasNextLine()) {

		decision = scanner.nextLine().split("   ");
		if (((int) (Double.parseDouble(decision[1]))) == 1) {
			return true;
		} else {
			return false;
		}
	}
	scanner.close();
	return false;
}        
main