Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Reading text file character by character into a 2d char[][] array

  1. #1
    Junior Member
    Join Date
    Apr 2019
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Reading text file character by character into a 2d char[][] array

    public static void main(String[] args)throws IOException 
    {
     
     
     
        File inFile = new File("grid.txt");                                 
        Scanner scanner = new Scanner(inFile);     
        String[] size = scanner.nextLine().split("\\s");         
     
        char[][] array = new char[10][10];
     
        for(int i=0; i < 10; i++) {
            array[i] = scanner.nextLine().toCharArray();
        }
     
        for(int k = 0; k < array.length; k++){
            for(int s = 0; s < array[k].length; s++){
                System.out.print(array[k][s] + " ");
            }
            System.out.println();
        }
     
         scanner.close();
     
     
    }


    What i am doing wrong ? please help
    I get java.util.NoSuchElementException: No line found

    File Format :
    eoksibaebl
    ropeneapop
    mbrflaoyrm
    gciarrauna
    utmorapply
    wnarmupnke
    ngrelclene
    alytueyuei
    fgrammarib
    tdcebykxka

  2. #2
    Member
    Join Date
    Sep 2018
    Location
    Virginia
    Posts
    284
    My Mood
    Cool
    Thanks
    0
    Thanked 38 Times in 36 Posts

    Default Re: Reading text file character by character into a 2d char[][] array

    Aren't you missing some size attributes at the beginning of your file? You *are* trying to read them from the same file.

    Regards,
    Jim

Similar Threads

  1. character reading
    By deependeroracle in forum Java Theory & Questions
    Replies: 5
    Last Post: September 19th, 2014, 12:06 PM
  2. Replacing text after a certain character or symbol in a text file
    By Ravekitty in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: November 25th, 2013, 02:40 PM
  3. Character string extraction from a text file
    By mond14 in forum Java Theory & Questions
    Replies: 4
    Last Post: November 14th, 2013, 08:12 PM
  4. The character '' is an invalid XML character exception getting
    By sumanta in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 9th, 2010, 12:13 PM
  5. Vietnamese Character Problem in JSP Report. Chinese and Thai Char OK
    By mrvora in forum JavaServer Pages: JSP & JSTL
    Replies: 7
    Last Post: October 23rd, 2009, 02:35 AM

Tags for this Thread