Scanner hasNextLine - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Scanner hasNextLine method.

This code example shows how to use the following methods:hasNextLine, nextLine
 
		file = new File(baseName + ".ref");
		if (file.exists()) {
			Scanner scanner = null;
			try { 
				scanner = new Scanner(file);
			} catch (FileNotFoundException e) {
				throw new RuntimeException(e);
			} 
			if (scanner.hasNextLine()) {
				file = new File(scanner.nextLine());
				if (file.exists()) {
					return ReferenceSequenceFileFactory.getReferenceSequenceFile(file);
				} 
			} 
		} 
		return null; 
	} 
 
	public static ReferenceSequenceFile findReferenceSequenceFileOrFail(Object... sources) { 
6
CodeRank
This code example shows how to use the following methods:close, hasNextLine, nextLine
	/** 
	 * Attempt to parse a string using a closed Scanner. 
	 */ 
	public static void writeToClosedStream(){ 
		try{ 
			Scanner in = new Scanner(System.in);
			System.out.println("Enter something: ");
			if (in.hasNextLine()){
				String myStr = in.nextLine();
				if(myStr.contains("something")){
					System.out.println("You entered something!");
				} 
				else{ 
					System.out.println("You didn't enter \"something\". Haha...");
				} 
			} 
			in.close();
			in.nextLine();
		}catch (IllegalStateException e){
			e.printStackTrace();

6
CodeRank
This code example shows how to use the following methods:hasNextLine, nextLine
        this.inputFile=file;
    } 
 
    public Map<String,String[]> parse(){
        try{ 
        Scanner sc = new Scanner(inputFile);
            while(sc.hasNextLine()){
                String line = sc.nextLine();
                String[] splitLine = line.split(" ");
                operations.put(splitLine[0],splitLine);
                return operations;
            } 
        }catch(FileNotFoundException e){
            System.out.println("Operations file not found.");
        } 
          return null; 
    } 
 
    public String[] getOperation(String op){
        return operations.get(op);
5
CodeRank
This code example shows how to use the following methods:hasNextInt, hasNextLine, nextLine
    public static void main(String[] args) {
        // TODO code application logic here 
        int userNumber;
        String userString;
         
        if(userInput.hasNextInt()){
        userNumber= userInput.nextInt();
        System.out.println("Number Input Successful");
        } 
        else if(userInput.hasNextLine()){
        userString=userInput.nextLine();
        System.out.println(userString);
        System.out.println("String Input Successfull");
        } 
         
        else  
            System.out.println("Failed. Try Again");
    } 
} 
5
CodeRank
This code example shows how to use the following methods:hasNextLine, nextLine
            url = null;
        } 
        if(url == null){
            return null; 
        } 
        Scanner s = new Scanner(url.openStream());
        while(s.hasNextLine()){
            return s.nextLine();
        } 
        return null; 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:hasNextLine, nextLine
	 
	private int getMaxSlots(){ 
		SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(context);
		String slot = "";
		try{ 
			Scanner scan = new Scanner(new File(u.getExternalDirectory() + "/BootManager/.zips/slots"));
			if(scan.hasNextLine())slot = scan.nextLine();
		}catch (FileNotFoundException e){
			e.printStackTrace();
		} 
		if(u.checkIfNumber(slot) == false){
			slot = shared.getString("slotNum", "4");
		} 
		return Integer.parseInt(slot);
	} 
	 
	private static String readRomName(String fname) {
        BufferedReader br;
        String line = null;
 
5
CodeRank
This code example shows how to use the following methods:hasNextLine, useDelimiter
	 *  
	 * Reference: http://weblogs.java.net/blog/pat/archive/2004/10/stupid_scanner_1.html 
	 */ 
	public String readLine()
	{ 
		if (scanner.hasNextLine())
		{			 
			return scanner.useDelimiter("\\A").next();
		} 
		 
		return null; 
	} 
	 
	public double getCurrentPrice(String input)
	{ 
		trade = input.indexOf("Last Trade:", 0);
		from = input.indexOf("<b><span", trade); 
		from = input.indexOf(">", from + 4);		
		to = input.indexOf("</span></b>", from);		
		price = input.substring(from + 1, to); 
5
CodeRank
This code example shows how to use the following methods:hasNextLine, useDelimiter
	 *  
	 * Reference: http://weblogs.java.net/blog/pat/archive/2004/10/stupid_scanner_1.html 
	 */ 
	public String readLine()
	{ 
		if (scanner.hasNextLine())
		{			 
			return scanner.useDelimiter("\\A").nextLine();
		} 
		 
		return null; 
	} 
	 
	public double getCurrentPrice(String input)
	{ 
		trade = input.indexOf("Last Trade:", 0);
		from = input.indexOf("<b><span", trade); 
		from = input.indexOf(">", from + 4);		
		to = input.indexOf("</span></b>", from);		
		price = input.substring(from + 1, to); 
5
CodeRank
This code example shows how to use the following methods:hasNextLine, useLocale
 
		try { 
			// first try to read file from local file system 
			File file = new File(s);
			if (file.exists()) {
				scanner = new Scanner(file, charsetName);
				scanner.useLocale(usLocale);
				return; 
			} 
 
			// next try for files included in jar 
			URL url = getClass().getResource(s);
 
			// or URL from web 
			if (url == null) {
				url = new URL(s);
			} 
 
			URLConnection site = url.openConnection();
			InputStream is = site.getInputStream();

5
CodeRank
This code example shows how to use the following methods:hasNextLine, useDelimiter
	 *  
	 * Reference: http://weblogs.java.net/blog/pat/archive/2004/10/stupid_scanner_1.html 
	 */ 
	public String readLine()
	{ 
		if (scanner.hasNextLine())
		{			 
			return scanner.useDelimiter("\\A").next();
		} 
		 
		return null; 
	} 
	 
	public double getCurrentPrice(String input)
	{ 
		trade = input.indexOf("Last Trade:", 0);
		from = input.indexOf("<b><span", trade); 
		from = input.indexOf(">", from + 4);		
		to = input.indexOf("</span></b>", from);		
		price = input.substring(from + 1, to); 
5
CodeRank

Related Scanner hasNextLine Questions & Answers:

hasNextLine Method Overview
Returns true if there is another line in the input of this scanner.
See Code Examples for other Java 8 Scanner Methods: