[RESOLVED] Retrieve numerical values from a text file
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: [RESOLVED] Retrieve numerical values from a text file

  1. #1
    Join Date
    Aug 2011
    Posts
    22

    [RESOLVED] Retrieve numerical values from a text file

    I have to retrieve numbers from a text file which is as shown in the attachment. I have written the following code snippet just to check if I am able to print the numbers in the file.
    Code:
    try {
    	Scanner myFile = new Scanner(new FileReader("C:/Documents and Settings/shikhau/workspace/SanNumber/freelast.txt"));
    	while (myFile.hasNext()) {
    		i = myFile.nextInt();
    		System.out.println(i);
    				
    	}
    }
    catch (FileNotFoundException e){
              System.out.println("Sorry! This file is not found");
    }
    I get the following exception:
    Code:
    Exception in thread "main" java.util.InputMismatchException
    	at java.util.Scanner.throwFor(Unknown Source)
    	at java.util.Scanner.next(Unknown Source)
    	at java.util.Scanner.nextInt(Unknown Source)
    	at java.util.Scanner.nextInt(Unknown Source)
    What do I do?
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center