Importing text file into 2D char array

Hey folks. I've aged a few years trying to figure this project out. Im trying to make a crossword puzzle and am having problems importing the answer letters into a 2D array of 15*15. The text file would look something like this:
LAPSE TAP RAH
AVAIL OLE ODE
BARGE PARADOX
etc
I have JTextFields that the user will answer and a button the user can press to see if the answers are right by comparing the 2D array answer with what the user inputted.-the user input would be scanned and put into a 2D array also.
How should i go about inserting each letter into an array? The spaces i would later need to make code to grey out the text field. This is what i have so far. Forgive me if its sloppy.
     class gridPanel extends JPanel
          //----Setting Grid variables
          private static final int ROWS = 15;
          private static final int COLS = 15;
          String[] letters = { "A", "B", "C", "D", "E" };// To test entering strings into array
           gridPanel()
             this.setBackground(Color.BLUE);
             //.......Making my JTextField grid for user input
             JTextField[][] grid = new JTextField[ROWS][COLS];
             for(int ROWS = 0; ROWS<grid.length; ROWS++)
                 for(int COLS = 0; COLS<grid.length; COLS++)
                     grid[ROWS][COLS] = new JTextField(1);
                     add(grid[ROWS][COLS]);
                 //grid[ROWS][COLS].setText("" + letters[0]);
             String an = null;
             StringTokenizer tokenizer = null;
             Character[][] answer = new Character[ROWS][COLS];
          try{
             BufferedReader bufAns = new BufferedReader( new FileReader("C:\\xwordanswers.txt"));
             for (int rowCurrent = 0; rowCurrent < ROWS; rowCurrent++)
          an = bufAns.readLine();
          tokenizer = new StringTokenizer(an);
          for (int colCurrent = 0; colCurrent < COLS; colCurrent++) {
          char currentValue = tokenizer.nextToken().charAt(0);//Needs to be changed to reflect each letter
                    answer[rowCurrent][colCurrent] = currentValue;
                System.out.println(currentValue);
          }catch (IOException ioex)           
                    System.err.println(ioex);
                    System.exit(1);
        }//xword graphics end
      This obviously prints the first char of each word, it also gives me an "Exception in thread "main" java.util.NoSuchElementException" error for some reason.
Any help is greatly appreciated.
John

If the file format is stored as follows:
APPLE
L A
PARSE
N E
PEAR then we can parse this into a 2D char array:
char[][] readMap(String fileName) {
    char[][] ret = new char[ROWS][COLS];
    FileInputStream FIS = new FIleInputStream(fileName);
    int i, j;
    for(i = 0; i < ROWS; i++)
        for(j = 0; j < COLS; j++)
            ret[i][j] = FIS.read();
    FIS.close();
    return ret;
}Then you can use the resulting 2D char array in your answer checking mechanism.
Hope this helps~
Alex Lam S.L.

Similar Messages

  • Import Text Files Into Apple Notes?

    Hello,
    Is there a way for me to automate importing text files into Apple Notes? I can certainly do this manually via copy/paste, but have over 700 files to transfer.
    Peace,
    Dr. Z.

    Automator is Apple's simple way to do tasks like this, but Notes app doesn't have any actions for this so I assume you need to use Applescript to do this. Double check Automator  - I am on 10.9 & maybe 10.10 added support for Notes in Automator? Enter 'Note' in the search field to see if Automator can make new Notes.
    There is an example for making notes at…
    http://www.macosxautomation.com/applescript/notes/04.html
    See the "Create New Stylized Note" script <- click script icon to download it, copy & paste seems to fail because of how the browser displays characters.
    You would need to adapt that script to import from the text files.
    I'm not sure you really want to do that anyway - Notes app has such poor support that putting serious data into it looks like a mistake - how difficult will it be to export data when Apple eventually abandon it? It seems like a toy app to me for new iPhone users, it;s unclear if it will ever be able to compete with other options. There are third party apps to export from Notes.app, but why rely on third parties? A notes app should allow you to import & export your data!
    Notational Velocity seems like a better choice…
    http://notational.net/
    It will handle notes as text files if you desire, so you can store them in Dropbox if you want. You can also set it to sync to Simplenote on iOS.
    http://simplenote.com/
    If you need images within notes or text styling you could use Evernote or one of the many other notes apps.
    Sorry to sound so negative on Notes.app, it's OK but I don't think its the best place to put over 700 notes.

  • Error importing text file into SQL Server when last column is null

    Hello all. Happy holidays!
    I'm trying to import a text file into a SQL Server table, and I get the error below when it gets to a row (row 264) that has null in the last column. I'm guessing the null jumbles up the delimiters somehow. The nulls are not errors, and I need to import
    them into the table with the rest of the rows. Any idea how I can do that?
    Thanks!
    [Flat File Source [1]] Error: Data conversion failed. The data conversion for column "XYZ" returned status value 2 and status text "The value could not be converted because of a potential loss of data.".
    [Flat File Source [1]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  The "output column "XYZ" (178)" failed because error code 0xC0209084 occurred, and the error row disposition on "output column "XYZ"
    (178)" specifies failure on error. An error occurred on the specified object of the specified component.  There may be error messages posted before this with more information about the failure.
    [Flat File Source [1]] Error: An error occurred while processing file "ABC.txt" on data row 264.
    [SSIS.Pipeline] Error: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.  The PrimeOutput method on component "Flat File Source" (1) returned error code 0xC0202092.  The component returned a failure code when the pipeline engine called PrimeOutput().
    The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing.  There may be error messages posted before this with more information about the failure.
    WeeLass

    Hi WeeLass,
    The error that” Data conversion failed. The data conversion for column "XYZ" returned status value 2 and status text "The value could not be converted because of a potential loss of data.".” is generally error message, and the error indicates
    that there is data type mismatch issue between the input columns and the output columns.
    Based on your description, the issue is that you trying to convert a column contains empty value from string to integer data type for the output column "XYZ" in Flat File Source [1]. Please note that we cannot type an empty value as integer data
    type column value, so the error occurs.
    To fix this issue, just as you did, we should convert the data type for the output column "XYZ" in Flat File Source [1] back to DT_WSTR or DT_STR, then use a derived column task to replace the current column (UBPKE542). But the expression should
    be like below:
    LEN(TRIM(UBPKE542)) > 0 ? (DT_I8)UBPKE542 : NULL(DT_I8)
    In this way, the data type of the column in SQL table would be int, and the empty value would be replaced with NULL.
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • How to copy data in text file into two-dimensional arrays?

    Greeting. Can somebody teach me how to copy the input file into two-dimensional arrays? I'm stuck in making a matrix with number ROWS and COLUMNS according to the data in "input.txt"
    import java.io.*;
    import java.util.*;
    public class array
        public static void main (String[] args) throws FileNotFoundException
        { Scanner sc = new Scanner (new FileReader("input.txt"));
            PrintWriter outfile = new PrintWriter("output.txt");
        int[][]matrix = new int[ROWS][COLUMNS];
    }my input.txt :
    a,b,c
    2,2,1
    1,1,1
    2,2,1
    3,3,1
    4,4,1
    5,5,1
    1,6,2
    2,7,2
    3,8,2
    4,9,2
    5,10,2

    import java.io.*;
    import java.util.*;
    public class array {
        public static void main(String[] args) throws IOException {
            FileInputStream in = null;
            FileOutputStream out = null;
    try {
        in = new FileInputStream("input.txt");
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String line = null;
        while ((line = reader.readLine()) != null) {
            String split[]=line.split(",");
    catch (IOException x) {
        System.err.println(x);
    } finally {
        if (in != null) in.close();
    }}}What after this?

  • Import text files into excel spreadsheet using automator

    Hello,
    I am trying to import a number of different text files into a single spreadsheet.  The content of each of the text files is the same (i.e. Same number of columns to be made) and each item is spac delimited.  I am trying to make it so that each of these text files will be entered into a single spreadsheet.  That is, one text file corresponds to one row of data and the second text file would correspond to the second row of data in the excel sheet.  Any ideas on how to do this?  I imagine this will require some sort of applescript but I'm not familiar with applescript at all!
    Thanks for your help!

    By the way, if anybody else has the same question I had:
    After trying this on my own, I recommend against doing what I did. I used the Excel macro language, Visual Basic for Applications. There are documented features in the Mac version that simply do nothing. I wasted a lot of time trying to find out why they wouldn't work. In other words, the online help told me they worked, but they didn't. I ended up with a combination of Automator and VBA and had to write my own code in VBA to duplicate the functionality that was supposed to be there.
    Also, it's my understanding that VBA on the Mac is a dead language and that Microsoft is concentrating on Excel's Applescript support, which appears to contain most (or all) of the functionality of VBA.
    I hope this helps someone else avoid making the same mistake I did!

  • Importing text file into search and redact window.

    I am in the search window under the search and redact tool.  I
    am trying to import a file that was originally an excel to populate the
    search multiple words window.  I read that text files can be imported.  I saved the file as a text file but it does not import.  I can import an adobe file but this gives me a list with a bunch of junk.  What am I missing?

    The dialog imports text files.
    Make sure that the file you are importing is a text file and has one word in every line.

  • Reading characters from a text file into a multidimensional array?

    I have an array, maze[][] that is to be filled with characters from a text file. I've got most of the program worked out (i think) but can't test it because I am reading my file incorrectly. However, I'm running into major headaches with this part of the program.
    The text file looks like this: (It is meant to be a maze, 19 is the size of the maze(assumed to be square). is free space, # is block, s is start, x is finish)
    This didn't paste evenly, but thats not a big deal. Just giving an idea.
    19
    5..................
    And my constructor looks like follows, I've tried zillions of things with the input.hasNext() and hasNextLine() to no avail.
    Code:
    //Scanner to read file
    Scanner input = null;
    try{
    input = new Scanner(fileName);
    }catch(RuntimeException e) {
    System.err.println("Couldn't find the file");
    System.exit(0);
    //Set the size of the maze
    while(input.hasNextInt())
    size = input.nextInt();
    //Set Limits on coordinates
    Coordinates.setLimits(size);
    //Set the maze[][] array equal to this size
    maze = new char[size][size];
    //Fill the Array with maze values
    for(int i = 0; i < maze.length; i++)
    for(int x = 0; x < maze.length; x++)
    if(input.hasNextLine())
    String insert = input.nextLine();
    maze[i][x] = insert.charAt(x);
    Any advice would be loved =D

    Code-tags sometimes cause wonders, I replaced # with *, as the code tags interprets # as comment, which looks odd:
    ******...*.........To your code: Did you test it step by step, to find out about what is read? You could either use a debugger (e.g., if you have an IDE) or system outs to get a clue. First thing to check would be, if the maze size is read correctly. Further, the following loops look odd:for(int i = 0; i < maze.length; i++) {
        for(int x = 0; x < maze.length; x++) {
            if (input.hasNextLine()) {
                String insert = input.nextLine();
                maze[x] = insert.charAt(x);
    }Shouldn't the nextLine test and assignment be in the outer loop? And assignment be to each maze's inner array? Like so:for(int i = 0; i < maze.length; i++) {
        if (input.hasNextLine()) {
            String insert = input.nextLine();
            for(int x = 0; x < insert.size(); x++) {
                maze[i][x] = insert.charAt(x);
    }Otherwise, only one character per line is read and storing a character actually should fail.

  • Reading from a text file into a 2D array

    How do you read from a text file and put it into a 2D array? Or if someone could guide me to where I can find the information?

    This tutorial shows how to read a file:
    http://java.sun.com/docs/books/tutorial/essential/io/scanfor.html
    This tutorial shows how to create arrays with multiple dimensions:
    http://java.sun.com/docs/books/tutorial/java/nutsandbolts/arrays.html

  • Importing text file into database

    Hi again,
    Could anyone give me any pointers on how to take a text file or csv file (or any other delimeted text file) and read the contents into java and then use the read in data to then insert the delimeted data into the table.
    i assume i have to read the delimeted data into a variable then parse the complete string with the delimeter and split the data up maybe in an array. Maybe this is completely wrong, im really unsure.
    any help would be greatly appreciated even a point in the right direction would be great :)
    kind regards.

    Well, atleast i dont know of a single method, which does this kind of nonhomogenous task!! Its not hard to impliment what you want-->
    //open the text file using FileInputStream & get the contents in a String variable
    //Tokenise it
    StringTokenizer st=new StringTokenizer(your_string_retrieved_from_file,delimiter);
    int i=0;
    while(st.hasMoreTokens())
    i++;
    //SQL Statement that inserts a string into database table(integer, varchar2)
    insert into test_table values(i,st.nextToken());
    Unless you are talking about putting the tokens as coloums in a single row, i dont find why this is a problem & if you are actually doing the above case, then you might wanna rethink your design

  • Importing Text Files  into Notes

    Having trouble reading imported text. I have IPod nano 3rd gen. It is checked to enable disc use. When I drop a .txt file into notes folder, then eject IPod, I can see the document titles in IPod/notes however, text displays as code (alot of 0's &1's and other garbled letters). Does anyone know why this happens and how I can solve this? I would greatly appreciate any suggestions.
    Thanks

    The files MUST be plain text files (possible sich text format as well) but not Word Documents and stuff like that. Simply taking a Word document and changing the extension from .doc to .txt won't do it for you, if that is what you tried.
    Patrick

  • Read words from a text file into an undefined array

    Dear all,
    Does anyone know how to read words in text file, seperated by all types of spaces ("_", "\n", "\t","\r","\f") and put them into a string array to be used later?
    So far I can read the words using the Tokenizer but can't assign to array:
    public class reader
    StringTokenizer tokenizer = new StringTokenizer(input);
    String[ ] array= null;  //unknown size of array
    int i=0;
                   while(tokenizer.hasMoreTokens())
                             array[i] = tokenizer.nextToken();
                             i++;
    Any suggestions welcome!
    thanks in advance!

    Hi
    sorry wrote in a hurry ;) din c the problem clearly
    there are two approaches
    1) best approach for your problem is Vector or ArrayList, these would make life easy for you.
    Always collections are better approach over arrays when the size is dynamic. However in your case the size cant be said to be DYNAMIC. coz the number of words will not grow / shrink during the runtime.. i know that number of words are not fixed but dynamic is something which will grow/shrink during runtime. but still collection is better approach.
    2)dirty approach
    use double dimensional array
    String arr[][] = null;
    then use one tokenizer for StringTokenizer(str,"\n");
    using countTokens on this will give you number of lines.
    use this to initialize array
    arr = new String[lineCount][];
    then iterate from 1 to lineCount and use 1 more tokenizer to get number of words for that line. use this number to initialize the column size for arr[i] like
    arr[i] = new String[wordCount];
    then store the token using nested for loops in this array
    go for the 1st one ;) 2nd one is hedious n time consuming but both will work ;)
    cheers
    amey

  • Import text file into repository

    Hello,
    I have created the physical data model in Designer 10g.  I was given the table and column descriptions in an excel spreadsheet.
    Is there any way I can import these descriptions into the repository?
    Thanks
    Cathy

    Hi
    I actually can't answer your question because I'm having quite similar problems. But maybe you haven't created the correct table defs (index, and so on).
    By the way, how have you done to export the database to a txt-file. I can't do this and don't know why. Is it posible that you post your vi? this would be great.
    Do you have a good book or example about ActiveX and MSAccess? I can't find anything and the tutorials couldn't help me.
    Thanks and I hope my tip could help you.
    Yves

  • Importing text file into table

    hello
    i have a text file which contains data like empno,date and one character . every day this file is updated with new records.
    now i want this data to get inserted to a table, whenever new record has been appended to the text file
    can i have query or some way to do this. i can do it through sql loader, but i will not have info when the data is appended to the text file.
    pls help
    thanks in advance
    sdsreenivas

    If you're on 8.0.3 (which has been desupported for a number of years), then SQL*Loader strikes me as your best option. You could write a batch process that re-loads the file periodically so you see changes or you could write a batch file that polls the timestamp for the file and calls SQL*Loader whenever it is updated.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Import txt file into user dictionary

    How to import text file into user dictionary through javascript? I can manually import txt file into user dictionary thru "Edit=>Spelling=>User dictionary...". But I don't know how to do it using javascript. Please advise.

    Advice? See in some version of the object-model reference under userDictionary. There you'll find a method called addWord(), which looks promising.
    Peter

  • How to import data from a text file into a table

    Hello,
    I need help with importing data from a .csv file with comma delimiter into a table.
    I've been struggling to figure out how to use the "Import from Files" wizard in Oracle 10g web-base Enterprise Manager.
    I have not been able to find a simple instruction on how to use the Wizard.
    I have looked at the Oracle Database Utilities - Overview of Oracle Data Pump and the Help on the "Import: Files" page.
    Neither one gave me enough instruction to be able to do the import successfully.
    Using the "Import from file" wizard, I created a Directory Object using the Create Directory Object button. I Copied the file from which i needed to import the data into the Operating System Directory i had defined in the Create Directory Object page. I chose "Entire files" for the Import type.
    Step 1 of 4 is the "Import:Re-Mapping" page, I have no idea what i need to do on this page. All i know i am not tying to import data that was in one schema into a different schema and I am not importing data that was in one tablespace into a different tablespace and i am not R-Mapping datafiles either. I am importing data from a csv file.
    For step 2 of 4, "Import:Options" page, I selected the same directory object i had created.
    For step 3 of 4, I entered a job name and a description and selected Start Immediately option.
    What i noticed going through the wizard, the wizard never asked into which table do i want to import the data.
    I submitted the job and I got ORA-31619 invalid dump file error.
    I was sure that the wizard was going to fail when it never asked me into which table do i want to import the data.
    I tried to use the "imp" utility in command-line window.
    After I entered (imp), i was prompted for the username and the password and then the buffer size as soon as i entered the min buffer size I got the following error and the import was terminated:
    C:\>imp
    Import: Release 10.1.0.2.0 - Production on Fri Jul 9 12:56:11 2004
    Copyright (c) 1982, 2004, Oracle. All rights reserved.
    Username: user1
    Password:
    Connected to: Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - Produc
    tion
    With the Partitioning, OLAP and Data Mining options
    Import file: EXPDAT.DMP > c:\securParms\securParms.csv
    Enter insert buffer size (minimum is 8192) 30720> 8192
    IMP-00037: Character set marker unknown
    IMP-00000: Import terminated unsuccessfully
    Please show me the easiest way to import a text file into a table. How complex could it be to do a simple import into a table using a text file?
    We are testing our application against both an Oracle database and a MSSQLServer 2000 database.
    I was able to import the data into a table in MSSQLServer database and I can say that anybody with no experience could easily do an export/import in MSSQLServer 2000.
    I appreciate if someone could show me how to the import from a file into a table!
    Thanks,
    Mitra

    >
    I can say that anybody with
    no experience could easily do an export/import in
    MSSQLServer 2000.
    Anybody with no experience should not mess up my Oracle Databases !

Maybe you are looking for