Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6616433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:34:55+00:00 2026-05-25T20:34:55+00:00

what makes it only be able to input 10*10 text files package game; import

  • 0

what makes it only be able to input 10*10 text files

package game;

import java.io.*;
import java.util.*;

public class Level {

static public void main(String[] args) throws IOException {
    File f = new File("Data1.txt");
    int[][] m = Map(f);
    for (int x = 0; x < m.length; x++) {
        for (int y = 0; y < m[x].length; y++) {
            System.out.print(m[x][y]);
        }
        System.out.println();
    }
}

public static int[][] Map(File f) throws IOException {

    ArrayList line = new ArrayList();
    BufferedReader br = new BufferedReader(new FileReader(f));
    String s = null;
    while ((s = br.readLine()) != null) {
        line.add(s);
    }
    int[][] map = new int[line.size()][];
    for (int i = 0; i < map.length; i++) {
        s = (String) line.get(i);
        StringTokenizer st = new StringTokenizer(s, " ");
        int[] arr = new int[st.countTokens()];
        for (int j = 0; j < arr.length; j++) {
            arr[j] = Integer.parseInt(st.nextToken());
        }
        map[i] = arr;
    }
    return map;
}
}

if i put in a text file that is
10*10 or less characters it works
otherwise it comes out with a numberformatexception

fixed

package game;

import java.io.*;
import java.util.*;

public class Level {

    static public void main(String[] args) throws IOException {
        File f = new File("Data1.txt");
        int[][] m = Map(f);
        for (int x = 0; x < m.length; x++) {
            for (int y = 0; y < m[x].length; y++) {
                System.out.print(m[x][y]);
            }
            System.out.println();
        }
    }

    public static int[][] Map(File f) throws IOException {

        ArrayList line = new ArrayList();
        BufferedReader br = new BufferedReader(new FileReader(f));
        String s = null;
        while ((s = br.readLine()) != null) {
            line.add(s);
        }
        int[][] map = new int[line.size()][];
        for (int i = 0; i < map.length; i++) {
            s = (String) line.get(i);
            char[] m = s.toCharArray();
            String[] n = new String[m.length];
            for (int t = 0; t<m.length;t++)
            {
                n[t] = ""+m[t];
            }

            int[] arr = new int[m.length];
            for (int j = 0; j < arr.length; j++) {
                arr[j] = Integer.parseInt(n[j]);
            }
            map[i] = arr;
        }
        return map;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:34:56+00:00Added an answer on May 25, 2026 at 8:34 pm

    Contrary to notes in the comments, your program seems to work with large files, and with long lines, as long as there are enough spaces.

    I think your issue is actually that whenever the text file has a token with more than 10 characters it throws a NumberFormatException.

    That would be because Integer.MAX_INT is 2147483647, which has 10 characters when written as a String, and Integer.parseInt just can’t handle more digits than that.

    You’re splitting on space and expecting everything to parse as an integer, and some of your numbers are too big for Java’s integer data type.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to be able to take an arbitrary text input that may have
I don't need this declaration because it only makes my code big and unreadable.
I tried using height: 100% but this makes the div only as high as
What Makes a Good Unit Test? says that a test should test only one
How to make exported .XLS file Editable Thid code makes .XLS File Read Only
how do i make only 1 object creation of any class?
How do I make Log4net only log Info level logs? Is that even possible?
I am writing an app that makes use of Object Output and Input Streams.
I would like to make an HTML text input field that always shows its
When I'm in certain text fields I want to be able to stop the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.