Get the content of a file into a array

Hy to all!I have txt file with the following content : 0 1 1 0
1 1 1 0
0 0 0 0. I want to extract the values to a bi-dimension array,like this: a[0][0] = 0,a[0][1] = 1,a[0][2] = 1....and so on.
Anybody could give a little help.THX

The first thing I can help you with is that this doesn't have anything to do with java serialization.
Secondly, if you are new to java, the best forum is "New To Java" forum.
Thirdly, make sure you have done a google search first for an answer because it is likely that many people have asked the same question before.
The follow search gets over 2 million hits. [http://www.google.co.uk/search?q=java+read+content+of+a+file+into+a+array]

Similar Messages

  • How to get the content of text file to write in JTextArea?

    Hello,
    I have text area and File chooser..
    i wanna the content of choosed file to be written into text area..
    I have this code:
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import javax.swing.JButton;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.*;
    public class Test_Stemmer extends JFrame {
    public Test_Stemmer() {
    super("Arabic Stemmer..");
    setSize(350, 470);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setResizable(false);
    Container c = getContentPane();
    c.setLayout(new FlowLayout());
    JButton openButton = new JButton("Open");
    JButton saveButton = new JButton("Save");
    JButton dirButton = new JButton("Pick Dir");
    JTextArea ta=new JTextArea("File will be written here", 10, 25);
    JTextArea ta2=new JTextArea("Stemmed File will be written here", 10, 25);
    final JLabel statusbar =
                  new JLabel("Output of your selection will go here");
    // Create a file chooser that opens up as an Open dialog
    openButton.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent ae) {
         JFileChooser chooser = new JFileChooser();
         chooser.setMultiSelectionEnabled(true);
         int option = chooser.showOpenDialog(Test_Stemmer.this);
         if (option == JFileChooser.APPROVE_OPTION) {
           File[] sf = chooser.getSelectedFiles();
           String filelist = "nothing";
           if (sf.length > 0) filelist = sf[0].getName();
           for (int i = 1; i < sf.length; i++) {
             filelist += ", " + sf.getName();
    statusbar.setText("You chose " + filelist);
    else {
    statusbar.setText("You canceled.");
    // Create a file chooser that opens up as a Save dialog
    saveButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    JFileChooser chooser = new JFileChooser();
    int option = chooser.showSaveDialog(Test_Stemmer.this);
    if (option == JFileChooser.APPROVE_OPTION) {
    statusbar.setText("You saved " + ((chooser.getSelectedFile()!=null)?
    chooser.getSelectedFile().getName():"nothing"));
    else {
    statusbar.setText("You canceled.");
    // Create a file chooser that allows you to pick a directory
    // rather than a file
    dirButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent ae) {
    JFileChooser chooser = new JFileChooser();
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    int option = chooser.showOpenDialog(Test_Stemmer.this);
    if (option == JFileChooser.APPROVE_OPTION) {
    statusbar.setText("You opened " + ((chooser.getSelectedFile()!=null)?
    chooser.getSelectedFile().getName():"nothing"));
    else {
    statusbar.setText("You canceled.");
    c.add(openButton);
    c.add(saveButton);
    c.add(dirButton);
    c.add(statusbar);
    c.add(ta);
    c.add(ta2);
    public static void main(String args[]) {
    Test_Stemmer sfc = new Test_Stemmer();
    sfc.setVisible(true);
    }could you please help me, and tell me what to add or to modify,,
    Thank you..                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    realahmed8 wrote:
    thanks masijade,
    i have filter the file chooser for only text files,
    but i still don't know how to use FileReader to put text file content to the text area (ta) ..
    please tell me how and where to use it..How? -- See the IO Tutorials on Sun for the FileReader (and I assume you know how to call setText and append in the JTextArea).
    Where? -- In the actionPerformed method (better would be a separate thread that is triggered through the actionPerformed method, but that is probably beyond you at the moment), of course.
    Give it a try.

  • I am thinking of buying a MacBook Air and am wondering how to get the content of my iPad into iTunes.

    I have iTunes on an old pc and am thinking of buying a MacBook Air. I am wondering how to get the content of my iPad on to the Mac as I know that sync only happens in one direction, from pc to device. I assume therefore that when I attach my pad to the new Mac it will sync to an empty iTunes and I will have lost all the content of my pad. I know I can restore purchases, but what about contacts, calendar, photos and music not purchased from apple. I have a fairly recent backup on a pen drive but it is a usb2 device and is formatted for a pc. Any advice would be appreciated.

    Do I copy my media library or from a backup.  I have a backup on my pc and on an external drive. This drive is usb2 and formatted for windows so I can't connect it to a MacBook Air to make the transfer.  Equally I don't think there is a way to connect the 2 computers via a cable ie usb2 one end and usb3 the other.  Will the computers talk to each other via wifi if I enable home share although I think this is only for music which still leaves contacts, mail etc.
    I am sorry to be such an ignoramus but any further help would be appreciated.

  • How to get the contents of jar file?

    Hi
    is there any way we can see the contents of jar file.(Since it is similar to zip file can we unzip it and see the contents)

    You can use:
    this->getClass().getResourceAsStream("/something.txt")
    where 'something.txt' is a file inside your .jar

  • Move the contents of old file into another  before writing in applcn srvr

    Hi Friends,
    As per the requirement I need to move the contents of the previous file into an archieve folder which is being created by the previous run of the program in the application server.
    After the old file has been moved I need to craete the new file in the directory.
    So at any time only one file should be present in the application server.
    All the previous files will be in the Archieve folder.
    Please suggest how can I move the contents of the privious file in the archieve directory.
    Thanks and regards,
    Smriti Singh
    Please do not duplicate post
    Edited by: Rob Burbank on Feb 24, 2009 11:16 AM

    Hi Smriti,
    check this
    1) use the function module  'EPS_GET_DIRECTORY_LISTING' --- to gett the details of files n application dir
    eq.
    call function 'EPS_GET_DIRECTORY_LISTING'
        exporting
          dir_name               = p_file
        tables
          dir_list               = it_dir_list
        exceptions
          invalid_eps_subdir     = 1
          sapgparam_failed       = 2
          build_directory_failed = 3
          no_authorization       = 4
          read_directory_failed  = 5
          too_many_read_errors   = 6
          empty_directory_list   = 7
          others                 = 8.
      if sy-subrc <> 0.
        message id sy-msgid type sy-msgty number sy-msgno
                with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      endif.
    2) then use this code to archive
    open dataset w_file1 for output in text mode encoding default. "Open Backup File
      if sy-subrc <> 0.
        write: /1 ' error creating file with status - ', sy-subrc.
        exit.
      endif.
      open dataset w_dirname for input in text mode encoding default."Open Real File
      if sy-subrc <> 0.
        error_flag = 'X'.
        write: /1 ' error opening input file with status - ', sy-subrc.
        exit.
      endif.
    *" To read the input file into a internal table
      do.
        read dataset w_dirname into inrec_lpcfab.
        if sy-subrc <> 0.
          exit.
        else.
          if not inrec_lpcfab is initial.
            append inrec_lpcfab.
            transfer inrec_lpcfab to w_file1 length 180.
          endif.
        endif.
      enddo.
      close dataset w_dirname.

  • My HD crashed, how do I get the content on my Ipad into Itunes

    I lost my itunes folder with all of my content; however the Ipad still has the content is there anyway to get it back to itunes? This includes movies, photos, etc.

    You can copy iTunes purchased content via File > Transfer Purchases when connected to iTunes. For content not purchased from Apple then have you not got a backup anywhere ? If not then you could try searching for third-party programs that can copy them off.
    For photos taken with the iPad, copied to it via the camera connection kit, or saved from emails/websites then see this page : http://support.apple.com/kb/HT4083
    For photos that were originally synced from a computer you will need a third-party app such as Simple Transfer (which has a free lite version called Simple Photo & Video Transfer) which can copy them off via your wifi network. But as photos are 'optimised' when they are synced to the iPad, any that you then copy back to a computer may not be exactly the same as they originally were on your computer.

  • How to save the contents of one file into another file?

    Hai,
    i'm trying to save the contents of an existing file into a new file...
    for example.. if i'm having a ms word file namely ss.doc..
    now i want to save itz contents into another file namele dd.doc..
    How shall i do it..
    Can an one plzz explain me...
    senthil.

    Hi, Senthil.
    This Forum is not a general discussion forum.
    You don't believe that the InDesign SDK is a general purpose API. Do you?
    I think you must post issues like this where they belong, in this case in a Microsoft Word Forum.
    Best regards.
    Oscar.

  • How to Display the content of Excel file into Webdynpro Table

    Hi Experts
    I am following the Blog to upload a file in to the webdynpro context,but my problem is after uploading a excel file i need to extract the content from that Excel file and that content should be displayed in the webdynpro table.Can any body please guide me how to read the content from excel and to Display in the Table.
    Thanks and Regards
    Kalyan

    HI,
    Take for example, if Excel file contains 4 fields,
    Add jxl.jar to JavaBuild path and Use this snippet
    File f=new File("sample.xls");
    Workbook w=Workbook.getWorkbook(f);
    Sheet sh=w.getSheet(0);
    int cols=sh.getColumns();
    int rows=sh.getRows();
    Cell c=null;
    String s1=null;
    String s2=null;
    String s3=null;
    String s4=null;
    ArrayList al=new ArrayList();
    int j=0;
    for(int i=1;i<rows;i++)
    ITableElement table=wdContext.createTableElementz
         s1=sh.getCell(0,i).getContents();
         s2=sh.getCell(1,i).getContents();
         s3=sh.getCell(2,i).getContents();
         s4=sh.getCell(3,i).getContents();
                             table.setName(s1);
         table.setAddress(s2);
         table.setDesignation(s3);
         table.setDummy(s4);
         al.add(j,table);
         j++;                    
    wdContext.nodeTable().bind(al);
    Regards
    LakshmiNarayana

  • Loading the Contents of a file into a JTable

    I am trying to load the content of a delimited (tab, comma, etc), into a JTable. The code is very simple and works for the most part. Here is some of it:
                   List tableRows = new ArrayList();
                   String lineItem = "";
                   InputStream in = new FileInputStream(fName);
                   InputStreamReader isr = new InputStreamReader(in);               
              BufferedReader br = new BufferedReader(isr);
         while((lineItem = br.readLine()) != null)
                        if(x == MAX)
                             break;
                        java.util.List rowData = new ArrayList();
                        StringTokenizer st = new StringTokenizer(lineItem, "\t");
                        while(st.hasMoreElements())
                             rowData.add(st.nextToken());
                        tableRows.add(rowData);     
                        x++;
    Basically, tableRows, ends up to be a List of Lists which I later use to populate the Object[][] for the JTable rows. This works perfect!
    My problem has to do with the tokenizer. In some situations, values in a line that is read contains "". For example an line read (quotes are showed only to distinquish values in the line):
    "item1", "item2", " ", "item4", " ", "item6", "item7"
    The tokenizer does not capture the " ". So instead of 7 tokens, it only sees 5.
    My question is, can someone tell me a better approach for tokenizing the string so that it captures everything?
    Thanks in advance,
    Augustine

    I am trying to load the content of a delimited (tab, comma, etc), into a JTable. The code is very simple and works for the most part. Here is some of it:
                   List tableRows = new ArrayList();
                   String lineItem = "";
                   InputStream in = new FileInputStream(fName);
                   InputStreamReader isr = new InputStreamReader(in);               
              BufferedReader br = new BufferedReader(isr);
         while((lineItem = br.readLine()) != null)
                        if(x == MAX)
                             break;
                        java.util.List rowData = new ArrayList();
                        StringTokenizer st = new StringTokenizer(lineItem, "\t");
                        while(st.hasMoreElements())
                             rowData.add(st.nextToken());
                        tableRows.add(rowData);     
                        x++;
    Basically, tableRows, ends up to be a List of Lists which I later use to populate the Object[][] for the JTable rows. This works perfect!
    My problem has to do with the tokenizer. In some situations, values in a line that is read contains "". For example an line read (quotes are showed only to distinquish values in the line):
    "item1", "item2", " ", "item4", " ", "item6", "item7"
    The tokenizer does not capture the " ". So instead of 7 tokens, it only sees 5.
    My question is, can someone tell me a better approach for tokenizing the string so that it captures everything?
    Thanks in advance,
    Augustine

  • How to copy the content of one file into another

    I have tried this code
    try {
                   fin = new FileInputStream("file path");
              catch(FileNotFoundException exc)
                   System.out.println("File not found");
                   return 0;
              catch(ArrayIndexOutOfBoundsException exc)
                   System.out.println("Usage: Showfile file");
                   return 0;
              while(true){
                   i=fin.read();
                   if(i==-1)
                        break;
                   cnt++;
              fin.close();*/
    now in this way i can lift one character at a time and copy it into another file (note i have not done the copy part in this code but that can be implemented) however this whole procedure is taking too much time if the size of the file is too big....kindly suggest another way to copy one file into another

    have you ever copied and pasted a large file in Windows or another OS? Larger files take more time to copy, that's just how it is.

  • Best method to handle the content of several files into only one ?

    Hi all,
    I am currently looking for the best solution to handle several file contents into a unique file, like a sort of archive. The goal is to develop a desktop application based on an API providing file encryption/decryption into a "box". I need to have a single file because I want to make it easy to travel on network, removable medias, etc. I found some solutions but lets say I'm starting from scratch, I don't want to influence your answers.
    So, for you, what is the best solution ?
    Look forward to getting your help

    BalusC wrote:
    Indeed, check the java.util.zip API. http://www.google.com/search?q=java.util.zip+api+javase+site:sun.com
    Also see http://java.sun.com/developer/technicalArticles/Programming/compression/
    Lots of sample code.

  • How to store the content of a file in oracle table.

    Hello,
    I have a .xml file in unix , how can i upload the content of that file into a column of a table in oracle?

    Did you look at the link posted in response to the OP? At a quick look, it seems fairly reasonable to me.
    John

  • Get the content from the PDF file IN WD ABAP View

    Hi all,
    I have a offline interactive form with data filled in that and save in my desktop. I want to upload the PDF content ( data ) into Web dynpro view.
    Currently i have the view designed with all the input box bound with the respective fields in the context and these fields are same as Adobe form fields.
    I have a UI element to browse and pick the file from the desktop. I have the upload button to upload the data into it.
    When i click the upload button it goes for dump. " No Enough Information for processing or Output"
    *Get the content from the file
      WD_CONTEXT->GET_ATTRIBUTE( EXPORTING NAME = 'PDFSOURCE'  IMPORTING VALUE = CONTENT ).
    In the above statement CONTENT is initial.  Hence dump. I have take this source from SDN Blog.
    Kindly help me where i went wrong.
    Thanks in advance.I

    Hi,
    try my solution (reading dunamic table, but you can read any data from pdf xml) described here:
    Dynamic Table data cannot be Read.
    Regards Jiri

  • To get the content of a pdf file in a particular position in text format

    I am troubling with geting the content of a pdf file in a particular position.I got the code to get the content of a pdf document as whole in text format.But i only need the content at a particular area.
    i am using PDFTextStripper class in pdfBox jar to get the content as whole.
    pls send some sample code
    pls help me
    Edited by: thomas00 on Sep 21, 2007 2:55 AM
    Edited by: thomas00 on Sep 21, 2007 3:08 AM

    pls any one reply

  • How to Convert the content in BLOB field into a PDF file...

    Hi,
    I am having PDF files stored in BLOB column of a table in Oracle Database (11G R2).
    I want to retrieve the files back and store them in hard disk. I am successful in storing the content as a file with '.doc' but if I store the file as '.pdf', adobe fails to open the file with error
    Adobe Reader could not open file 'xxx.pdf' because it is either not a supported file type or because the file has been damaged (for example it was sent as an email attachment and wasn't correctly decoded)
    I am using following example code to achieve my goal...
    Declare
    b blob;
    c clob;
    buffer VARCHAR2(32767);
    buffer_size CONSTANT BINARY_INTEGER := 32767;
    amount BINARY_INTEGER;
    offset NUMBER(38);
    file_handle UTL_FILE.FILE_TYPE;
    begin
    select blob_data into b from blobdata where id=1;
    c := blob2clob(b);
    file_handle := UTL_FILE.FOPEN('BLOB2FILE','my_file.pdf','w',buffer_size);
         amount := buffer_size;
         offset := 1;
         WHILE amount >= buffer_size
         LOOP
              DBMS_LOB.READ(c,amount,offset,buffer);
              -- buffer:=replace(buffer,chr(13),'');
              offset := offset + amount;
              UTL_FILE.PUT(file_handle,buffer);
              UTL_FILE.FFLUSH(file_handle);
         END LOOP;
         UTL_FILE.FCLOSE(file_handle);
    end;
    create or replace FUNCTION BLOB2CLOB ( p_blob IN BLOB ) RETURN CLOB
    -- typecasts BLOB to CLOB (binary conversion)
    IS
    || Purpose : To Convert a BLOB File to CLOB File
    || INPUT : BLOB File
    || OUTPUT : CLOB File
    || History: MB V5.0 24.09.2007 RCMS00318572 Initial version
    ln_file_check NUMBER;
    ln_file_size NUMBER;
    v_text_file CLOB;
    v_binary_file BLOB;
    v_dest_offset INTEGER := 1;
    v_src_offset INTEGER := 1;
    v_warning INTEGER;
    lv_data CLOB;
    ln_length NUMBER;
    csid VARCHAR2(100) := DBMS_LOB.DEFAULT_CSID;
    V_LANG_CONTEXT NUMBER := DBMS_LOB.DEFAULT_LANG_CTX;
    BEGIN
    DBMS_LOB.createtemporary (v_text_file, TRUE);
    SELECT dbms_lob.getlength(p_blob) INTO ln_file_size FROM DUAL;
    DBMS_LOB.converttoclob (v_text_file, p_blob, ln_file_size, v_dest_offset, v_src_offset, 0, v_lang_context, v_warning);
    SELECT dbms_lob.getlength(v_text_file) INTO ln_length FROM DUAL;
    RETURN v_text_file;
    END;

    user755667 wrote:
    Hi,
    I am having PDF files stored in BLOB column of a table in Oracle Database (11G R2).
    I want to retrieve the files back and store them in hard disk. I am successful in storing the content as a file with '.doc' but if I store the file as '.pdf', adobe fails to open the file with error
    Adobe Reader could not open file 'xxx.pdf' because it is either not a supported file type or because the file has been damaged (for example it was sent as an email attachment and wasn't correctly decoded)
    I am using following example code to achieve my goal...
    Declare
    b blob;
    c clob;
    buffer VARCHAR2(32767);
    buffer_size CONSTANT BINARY_INTEGER := 32767;
    amount BINARY_INTEGER;
    offset NUMBER(38);
    file_handle UTL_FILE.FILE_TYPE;
    begin
    select blob_data into b from blobdata where id=1;
    c := blob2clob(b);
    file_handle := UTL_FILE.FOPEN('BLOB2FILE','my_file.pdf','w',buffer_size);
         amount := buffer_size;
         offset := 1;
         WHILE amount >= buffer_size
         LOOP
              DBMS_LOB.READ(c,amount,offset,buffer);
              -- buffer:=replace(buffer,chr(13),'');
              offset := offset + amount;
              UTL_FILE.PUT(file_handle,buffer);
              UTL_FILE.FFLUSH(file_handle);
         END LOOP;
         UTL_FILE.FCLOSE(file_handle);
    end;
    create or replace FUNCTION BLOB2CLOB ( p_blob IN BLOB ) RETURN CLOB
    -- typecasts BLOB to CLOB (binary conversion)
    IS
    || Purpose : To Convert a BLOB File to CLOB File
    || INPUT : BLOB File
    || OUTPUT : CLOB File
    || History: MB V5.0 24.09.2007 RCMS00318572 Initial version
    ln_file_check NUMBER;
    ln_file_size NUMBER;
    v_text_file CLOB;
    v_binary_file BLOB;
    v_dest_offset INTEGER := 1;
    v_src_offset INTEGER := 1;
    v_warning INTEGER;
    lv_data CLOB;
    ln_length NUMBER;
    csid VARCHAR2(100) := DBMS_LOB.DEFAULT_CSID;
    V_LANG_CONTEXT NUMBER := DBMS_LOB.DEFAULT_LANG_CTX;
    BEGIN
    DBMS_LOB.createtemporary (v_text_file, TRUE);
    SELECT dbms_lob.getlength(p_blob) INTO ln_file_size FROM DUAL;
    DBMS_LOB.converttoclob (v_text_file, p_blob, ln_file_size, v_dest_offset, v_src_offset, 0, v_lang_context, v_warning);
    SELECT dbms_lob.getlength(v_text_file) INTO ln_length FROM DUAL;
    RETURN v_text_file;
    END;I skimmed this and stopped reading when i saw the BLOB to CLOB function.
    You can't convert binary data into character based data.
    So very likely this is your problem.

Maybe you are looking for

  • User Exit or BADI for the Bank validation in BP transaction

    Hi All,     My requirement goes like this, my customer wants to validate the bank keys whether the deletion flag is marked or not and if marked then throw the error message, in BP transaction. But when i was searching for the user exit or a BADI duri

  • Virus Detected (403), Your file could not be uploaded because it contains a virus.

    From a Windows 7 Ultimate PC I tried to upload a PDF portfolio containing 35 PDFs. The upload failed with the message "Virus Detected (403), Your file could not be uploaded because it contains a virus." It is highly unlikely that this PDF portfolio o

  • Flash MX 2004 & QT 7.1.5

    I know you had to use Flash Player 5 for previous QT export from Flash, but does the latest QT support Flash at all? There isn't even a place to check Flash support in QT 7.1.5's advanced settings that I can see. Is there any way around this? It work

  • Hprof doesn't show cpu times of own methods

    Hi, I'm using hprof like this on Java 1.4.2_18: -Xrunhprof:cpu=times,file=/some/file.txt This generates output like this: 1258 0.01% 91.01% 2899 2050 org.apache.axis.encoding.SerializationContext.startElement 1259 0.01% 91.02% 31041 1051 java.util.Ar

  • Packaging large InDesign document - won't copy all links

    I'm trying to Package a 1,000-page InDesign document that has about 375 links for our archive. When I go through the packaging process, however, it only saves about a dozen images or so in the designated folder. Any ideas why it's not taking the time