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?

Similar Messages

  • How to read a whole text file into a pl/sql variable?

    Hi, I need to read an entire text file--which actually contains an email message extracted from a content management system-- into a variable in a pl/sql package, so I can insert some information from the database and then send the email. I want to read the whole text file in one shot, not just one line at a time. Shoud I use Utl_File.Get_Raw or is there another more appropriate way to do this?

    how to read a whole text file into a pl/sql variable?
    your_clob_variable := dbms_xslprocessor.read2clob('YOUR_DIRECTORY','YOUR_FILE');
    ....

  • How to write data to text file using external tables

    can anybody tell how to write data to text file using external tables concept?

    Hi,
    Using external table u can load the data in your local table in database,
    then using your local db table and UTL_FILE pacakge u can wrrite data to text file
    external table
    ~~~~~~~~~~~
    http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_7002.htm#i2153251
    UTL_FILE
    ~~~~~~~~~
    http://download-east.oracle.com/docs/cd/B19306_01/appdev.102/b14258/u_file.htm#sthref14093
    Message was edited by:
    Nicloei W
    Message was edited by:
    Nicloei W

  • How to copy data in ASO cube across two scenario's?

    How to copy data in ASO cube across two scenario's?

    There are multiple ways to do it.
    How is the source scenario sourced? If it is populated using load rules, then why don't change it in the rule itself?
    Regards
    Celvin

  • Loading data from text file into ListBox

    I have data in a text file that I want to load into a
    listbox... I have fully mastered handling strings and arrays so I'm
    going to need some help...
    I was wondering how do I get flash to load a text file that
    contains the data below.. and display it line for line like I want
    it to list down the component
    "Launch;7.1.7.6"
    "Engine;7.1.7.6"
    "OSX;7.0.0.2" (or something close to that)
    and I was wondering how do i just get it to take it fromt he
    file.. line for line from where it says exeversion in the file and
    list it in the listbox...
    I'm really thankful to anybody that helps.
    Data in text file:
    quote:
    exeversion=Launch;7.1.7.6;
    exeversion=Engine;7.1.7.6;
    exeversion=LinuxX86;7.0.0.2;
    exeversion=LinuxPPC;7.0.0.2;
    exeversion=LinuxMIPS;7.0.0.2;
    exeversion=OSX;7.0.0.2;
    exeversion=Config;7.1.7.6;
    exeversion=UI;7.1.7.7;
    exeversion=JAVA;7.0.4.5;

    nobody cna help me? i really need to know or have a tutorial
    or something so i can learn from it... i really appreciate anyone
    who helps

  • How can i feed a text file into a Hashtable?

    Hi,
    im working on my third year project, im new to java and am struggling a little with writing the code.
    I need to feed a text file into my program and insert it into a hashtable. I presume i'll be using an input stream to feed the file in, how do i go about placin the text file into a hashtable??
    please help!

    ok, so im trying to code an authorship attribution
    program. the first part of the program need to
    compare a text file A (list of words), with another
    two text files B and C. Compare how? Do you want to know how many times certain words from list A appear in files B and C?
    The words in list A will first be compared to those
    in list B and than list C. I was wondering if there
    was a way of inserting file A,A Map is a list of key/value pairs, so what do you mean by inserting here? What are you inserting? What would the keys and values here be?
    followed by B,
    comparing the two files.....than inserting file C and
    comparing it with A??
    Does this make sense??Not quite, but it might just be me.

  • Unable to Upload data from text file into BEx Analyzer selection screen

    Hi,
    No response from BEx Analyzer when I am trying to upload around 40,000 material from text file into BEx Analyzer selection screen using "Upload selections" options. But I am able to upload only 10,000 material from text file.  I never faced same kind of issue when I am using BEx Analyzer 3.x.  Please let me know I have to change any settings related to BEx or any other.
    Thanks
    Sri Krishna Ponnada.

    Hello
    It seems you are reaching the .NET memory limitation informed in note 1040454.
    Because 3.5 does not use .NET it can work that.
    Regards,
    Ricardo

  • How to extract data from  text file to database table

    Hi ,
    I am trying to upload  data in text file to database table  using GUI_UPLOAD function .what would be the program for that.
    thanks in advance.

    Hi,
    I don't think you have a standard sap program to upload data from file to database table...
    Instead you can create a custom program like this..
    DATA: T_FILEDATA(1000) OCCURS 0 WITH HEADER LINE.
    DATA: T_ZTABLE LIKE ZTABLE OCCURS 0 WITH HEADER LINE.
    CALL FUNCTION 'GUI_UPLOAD'
      EXPORTING
        filename                      = 'C:\TEST.TXT'
      tables
        data_tab                      = T_FILEDATA
    EXCEPTIONS
       FILE_OPEN_ERROR               = 1
       FILE_READ_ERROR               = 2
       NO_BATCH                      = 3
       GUI_REFUSE_FILETRANSFER       = 4
       INVALID_TYPE                  = 5
       NO_AUTHORITY                  = 6
       UNKNOWN_ERROR                 = 7
       BAD_DATA_FORMAT               = 8
       HEADER_NOT_ALLOWED            = 9
       SEPARATOR_NOT_ALLOWED         = 10
       HEADER_TOO_LONG               = 11
       UNKNOWN_DP_ERROR              = 12
       ACCESS_DENIED                 = 13
       DP_OUT_OF_MEMORY              = 14
       DISK_FULL                     = 15
       DP_TIMEOUT                    = 16
       OTHERS                        = 17
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    LOOP AT T_FILEDATA.
      T_ZTABLE = T_FILEDATA.
      APPEND T_ZTABLE.
    ENDLOOP.
    MODIFY ZTABLE FROM TABLE T_ZTABLE.
    COMMIT WORK..
    Thanks,
    Naren

  • 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

  • How can I sort a sequence files into two new folders in Automator?

    I have a folder with 2000 files. I need to sort these files into two folders. I have sequentially renamed the files in automator so that a number is the first character of each file. I need to put the odd numbered files in folder one and the even numbered ones in folder two.
    I can do this sort in a spreadsheet. How do I get the resuls of the spreadsheet sort back into automator?
    Or is there a better way to do this within Automator?
    G4 17 PB   Mac OS X (10.4.2)  

    Open the Script Editor in the /Applications/AppleScript/ folder and enter the following:
    tell application "Finder"
    set source_folder to folder "folder:with:2000:items"
    set folder_1 to folder "folder 1"
    set folder_2 to folder "folder 2"
    repeat with this_item in (get items of source_folder)
    if (item 1 of (get name of this_item)) mod 2 is 1 then --odd number
    move this_item to folder_1
    else
    move this_item to folder_2
    end if
    end repeat
    end tell
    Insert the paths to the actual folders in lines 2, 3, and 4.
    (14737)

  • Read file into multi-dimensional array - ideal world...

    Hello all, would be very grateful if you could help me...
    I have a file which has a format...
    string1a,string1b
    string2a,string2bi need to read this file, which will have a variable length, into a two dimensional array.
    the code below is just demonstrating my approach...
              List lines = new ArrayList();
              BufferedReader in = new BufferedReader(new FileReader(filename));
              String str;
              while ((str = in.readLine()) != null) {
                   lines.add(str.split(","));
              in.close();but when i later try and invoke the toArray() method of lines it complains about unsafe or unchecked operations.
    does any have any pointers about the best way to read a file into a multi-dimensional array? is it best practice to use the interface List?
    thanks in advance
    poncenby

    This is just a List of Lists - no worries there.
    Sounds like your toArray code is incorrect. Post that.
    %

  • How to save data from text file in databse for a transaction...

    Hi Guys,
    I have a text file which has some data related relevant to transaction VA01 separated by tabs.
    Now instead of going in the transaction in VA01 and thne feeding the data manually, I would like this data
    to get read automatically from the text file and get processed field by field for transaction VA01 and thne get saved.
    How do I achieve this ? Do I have to use SHDB or some other method ?a

    hi tushar,
    REPORT  ZCALL_TRANS_TAB1                      .
    TABLES: LFA1,LFBK,lfb1.
    *& internal table declaration
    data: BEGIN OF it_vendor occurs 0,
           LIFNR LIKE LFA1-LIFNR,
           bukrs like lfb1-bukrs,
           END OF it_vendor.
    DATA: BEGIN OF IT_BANK occurs 0,
          LIFNR LIKE LFA1-LIFNR,
          BANKS LIKE LFBK-BANKS,
          BANKL LIKE LFBK-BANKL,
          BANKN LIKE LFBK-BANKN,
          koinh like lfbk-koinh,
          END OF IT_BANK.
    data: it_bdcdata like bdcdata occurs 0 with header line.
    data: it_messages like bdcmsgcoll occurs 0 with header line.
    *selection screen.
    selection-screen: begin of block b1 with frame.
    parameters: p_file like rlgrap-filename default 'c:/vendor.txt'
    obligatory.
    parameters: p_file1 like rlgrap-filename default 'c:/xyz.txt'
    obligatory.
    selection-screen: end of block b1.
    *at selection screen.
    at selection-screen on value-request for p_file.
    perform f4_help using p_file.
    at selection-screen on value-request for p_file1.
    perform f4_help1 using p_file1.
    *start of selection
    start-of-selection.
    *******uploading file
    perform upload_file using p_file P_FILE1.
    ******open session.
    perform populate_data.
    *&      Form  f4_help
          text
         -->P_P_FILE  text
    form f4_help  using    p_p_file.
    data: l_file type ibipparms-path.
    call function 'F4_FILENAME'
    importing
       file_name           = l_file.
       p_file = l_file.
    endform.                    " f4_help
    *&      Form  POPULATE_DATA
          text
    -->  p1        text
    <--  p2        text
    form populate_data .
    DATA: L_STRING TYPE STRing.
    DATA: L_COUNTER(2) TYPE n.
    loop at it_vendor.
    perform bdc_dynpro      using 'SAPMF02K' '0106'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'RF02K-D0130'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '/00'.
    perform bdc_field       using 'RF02K-LIFNR'
                                   it_vendor-lifnr.
    perform bdc_field       using 'RF02K-BUKRS'
                                  it_vendor-bukrs.
    perform bdc_field       using 'RF02K-D0130'
                                  'X'.
    perform bdc_dynpro      using 'SAPMF02K' '0130'.
    perform bdc_field       using 'BDC_CURSOR'
                                  'LFBK-bankn(03)'.
    perform bdc_field       using 'BDC_OKCODE'
                                  '=UPDA'.
    ******CALL TRANSACTION.
    call transaction 'FK02' using it_bdcdata mode 'A'
                            messages into it_messages.
    write:/ sy-subrc.
    perform format_messages.
    clear it_bdcdata.
    refresh it_bdcdata.
    endloop.
    endform.                    " POPULATE_DATA
    *&      Form  FORMAT_MESSAGES
          text
    -->  p1        text
    <--  p2        text
    form format_messages .
    data: l_msg(100).
    loop at it_messages.
    call function 'FORMAT_MESSAGE'
    exporting
       id              = it_messages-msgid
       lang            = sy-langu
       no              = it_messages-msgnr
       v1              = it_messages-msgv1
       v2              = it_messages-msgv2
       v3              = it_messages-msgv3
       v4              = it_messages-msgv4
    importing
       msg             = l_msg
    exceptions
       not_found       = 1
       others          = 2
    write:/ l_msg.
      endloop.
    endform.                    " FORMAT_MESSAGES
    *&      Form  bdc_dynpro
          text
         -->P_0173   text
         -->P_0174   text
    form bdc_dynpro  using    value(p_program)
                              value(p_screen).
    it_bdcdata-program = p_program.
    it_bdcdata-dynpro = p_screen.
    it_bdcdata-dynbegin = 'X'.
    append it_bdcdata.
    clear it_bdcdata.
    endform.                    " bdc_dynpro
    *&      Form  bdc_field
          text
         -->P_0178   text
         -->P_0179   text
    form bdc_field  using    value(p_fnam)
                             value(p_fval).
    it_bdcdata-fnam = p_fnam.
    it_bdcdata-fval = p_fval.
    append it_bdcdata.
    clear it_bdcdata.
    endform.                    " bdc_field
    *&      Form  upload_file
          text
         -->P_P_FILE  text
         -->P_P_FILE1  text
    form upload_file  using    p_p_file
                               p_p_file1.
    CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
      CODEPAGE                      = ' '
       FILENAME                      = P_P_FILE
       FILETYPE                      = 'DAT'
      HEADLEN                       = ' '
      LINE_EXIT                     = ' '
      TRUNCLEN                      = ' '
      USER_FORM                     = ' '
      USER_PROG                     = ' '
      DAT_D_FORMAT                  = ' '
    IMPORTING
      FILELENGTH                    =
      TABLES
        data_tab                      = IT_VENDOR
    EXCEPTIONS
      CONVERSION_ERROR              = 1
      FILE_OPEN_ERROR               = 2
      FILE_READ_ERROR               = 3
      INVALID_TYPE                  = 4
      NO_BATCH                      = 5
      UNKNOWN_ERROR                 = 6
      INVALID_TABLE_WIDTH           = 7
      GUI_REFUSE_FILETRANSFER       = 8
      CUSTOMER_ERROR                = 9
      NO_AUTHORITY                  = 10
      OTHERS                        = 11
    IF sy-subrc <> 0.
    MESSAGE I000(ZZ) WITH 'UNABLE TO UPLOAD'.
    STOP.
    ENDIF.
    *******UPLOADING BANK DETAILS
    CALL FUNCTION 'WS_UPLOAD'
    EXPORTING
      CODEPAGE                      = ' '
       FILENAME                      = P_P_FILE1
       FILETYPE                      = 'DAT'
      HEADLEN                       = ' '
      LINE_EXIT                     = ' '
      TRUNCLEN                      = ' '
      USER_FORM                     = ' '
      USER_PROG                     = ' '
      DAT_D_FORMAT                  = ' '
    IMPORTING
      FILELENGTH                    =
      TABLES
        data_tab                      = IT_BANK
    EXCEPTIONS
       CONVERSION_ERROR              = 1
       FILE_OPEN_ERROR               = 2
       FILE_READ_ERROR               = 3
       INVALID_TYPE                  = 4
       NO_BATCH                      = 5
       UNKNOWN_ERROR                 = 6
       INVALID_TABLE_WIDTH           = 7
       GUI_REFUSE_FILETRANSFER       = 8
       CUSTOMER_ERROR                = 9
       NO_AUTHORITY                  = 10
       OTHERS                        = 11
    IF sy-subrc <> 0.
    MESSAGE I000(ZZ) WITH 'UNABLE TO UPLOAD'.
    STOP.
    ENDIF.
    endform.                    " upload_file
    *&      Form  f4_help1
    form f4_help1  using    p_p_file1.
    data:l_file1 type ibipparms-path.
    CALL FUNCTION 'F4_FILENAME'
    IMPORTING
       FILE_NAME           = l_file1.
       p_file1 = l_file1.
    endform.                    " f4_help1

  • How to retrieve data from xml file into obiee reports

    Hi all,
    I've got a situation here. A xml file is stored as blob in oracle database table. Now i need to retrieve data/info from that xml file into obiee reports. How am i supposed to proceed with this ?

    I will go for a table function:
    http://gerardnico.com/wiki/database/oracle/table_function
    In two words, you can create a function that behave as a table. Then you create a function to pick up your xml, you parse it and you send back the rows.
    I know that Oracle has also a library for XML files but I never use it until now.
    Success
    Nico

  • How to display data in text file in column format

    hi
    i am acquiring data from an oscilloscope.
    wen i save the data in a text file using wite to speadsheet string, all the voltage values r displayed first and then the time values... besides its tab delimited
    how can i display it such that the time values r in one column and the voltyage values r in the other column
    thanx
    Solved!
    Go to Solution.

    Hi,
    I think you are collecting data at the same time and as aeastet told building an array will help. the example attached will give you an idea.. Though i am not sure whether this will solve your problem or not.
    Regards,
    Nitzz
    (Kudos are always Welcome, Mark as a solution if it is the One)
    Attachments:
    Untitled 1.vi ‏7 KB

  • How to transfer data from excel files into z-tables

    Please help me with a code which transfers data from excel file to z-table.
    Thanks in advance
    Shuvir

    Hi Daniel,
    Export Data
    Purpose
    Use this procedure to export SAP data to a local file such as Microsoft Excel.
    Menu Path
    Use the following menu path to begin this process:
    ·         SystemèListèSaveèLocal File
    Helpful Hints
    When reviewing fields, R = Required,  O = Optional and C = Conditional.
    Procedure
    1.       Start the transaction using the menu path or transaction code.
          Whatever Data You Want to Export
    2.       Select SystemèListèSaveèLocal File.  This works well for any data in SAP.  This is the only option for the top-level (first page) of a report. 
    In a drill-down view within a report the Local File button  on the toolbar may be used and has the same options.
          Choose File Format
    3.       Click  .
    4.       Click  to continue.  If prompted for a format after choosing Spreadsheet, select Excel Table to get an Excel file that can be modified more easily.
          Choose File Save Location Step 1
    5.       Click  to the right of the Directory field to choose a different location.
          Choose File Save Location Step 2
    6.       Click  or browse your computer to locate the directory where you want to save your file.
    7.       Complete the following field:
    ·         File name:
        You must add the proper file extension to the name of your file (.xls for Excel, .rtf for Rich Text, .html for HTML).  The file extension tells your computer what program to open the file with.  If you do not have the file extension at the end, you may not be able to open it.
    8.       Click  to continue.
          Generate File in Location and Format Selected
    9.       Click  to create the file in the location and format selected.  In this example the file was named "example.xls" and saved on the desktop.
    Result
    You have completed the export process.
    thanks
    karthik

Maybe you are looking for

  • [SOLVED] Network Manager / nm-applet problems on fresh installation

    I have just carried out a fresh re-installation of Arch on my old netbook, following a self-inflicted crash! Previously, networking worked perfectly, but since the new installation, nm-applet is behaving strangely. All connections (wired and wireless

  • Operations on tree nodes

    Hi everyone, it's me again, with another issue =) I need to be able to rename all node under a specific node in a hierarchy. Let's take this table and the following sample data. CREATE TABLE organisations   organ_id NUMBER(10) PRIMARY KEY,   parent_i

  • Sorting Apps - Other Wishlists - Few Gripes

    This is my first smartphone, 10 days now on Fascinate and its been good. I'm an IT network admin, so I'm used to apps and new issues, tech savy person. Using lookout for antivirus.  Seems ok. I do wish I could organize my apps,  like a games folder,

  • I received a T420 with B2 Chipset stepping. What to do?

    Last week I received a T420 (4180 W1G). Today I checked the Chipset Stepping by using this Webside (german) http://www.heise.de/newsticker/meldung/Intel-Bug-C​hipsatz-Erkennung-2-Update-1182613.html  The result is, that my brand new T420 has got the

  • Can't connect to mail service

    I cannot connect to the mail service, I have tried hard reset and it still does not work!!!