Reading a file and put it in a String

I have a file and I want to put its rows in an array of strings
I've done that
File file = new File("./arguments/tabsArguments.txt");
FileReader fileReader = new FileReader(file);
String mystring;
fileReader.read(mystring,0,20);
for (int i=0;i<i_string.length();i++)
tabs=i_string;
fileReader.read(mystring,0,20);
It throws this exception
java.io.StreamCorruptedException: invalid stream header.
I've done by myself the file "tabsArguments.txt"
and it's a simple list of string.help please!

Nothing in the code you posted can cause StreamCorruptedException to be thrown. Also, the code fragment you posted can't even be compiled because mystring is used before initialization, FileReader doesn't have a method with the signature read(String, int, int), and variable "tabs" is not defined. StreamCorruptedException is thrown "when control information that was read from an object stream violates internal consistency checks." This suggests that you use ObjectInputStream somewhere but I can't see where. http://java.sun.com/j2se/1.4.1/docs/api/java/io/StreamCorruptedException.html
so from now on please post the actual code you have problems with...
see http://javaalmanac.com/egs/java.io/ReadLinesFromFile.html

Similar Messages

  • Reading .txt files and put it into a TextArea

    Hi all,
    I got a problem! I have to make something like a messenger.
    I want to put the written text into a .txt file, after that I have to get the text out of the .txt file and put in into a TextArea.
    I would ike it to to that like this:
    ">User 1
    Hello!
    >User 2
    Hi!
    Now here are my questions:
    1: What is the moet easy way to do this ?
    2: How could i put Enters into a .txt file with Java ?
    3: How could i read all the text from the .txt file and put it into a TextArea WITH ENTERS ?
    Thanks for your help!
    Greetings, Jasper Kouwenberg

    use JTextArea.read(new FileReader(fileName)) for reading.
    and JTextArea.write(new FileWriter(fileName)) for writing.
    The enters should be ok if the user press enter and adds a new line ("\n") to the text area component.
    It will save the enter in the text file and load it correctly back to the text area.
    If you want to add enter programmatically just add "\n" string to the text area component.

  • Read the file and write the data into string or int

    Ok, here's another rookie question.
    I got to read the line from the file and store it in the memory as string or integer.
    I wrote this code:
    File inputFile = new File("c:/xxx.yyy");
    String outputString = new String();
    FileReader c1 = new FileReader(inputFile);
    StringWriter d1 = new StringWriter(outputString);
    int data;
             while((data = c1.read()) != -1)
                 d1.write(data);
                 System.out.println(data);
             c1.close();
             d1.close();This is how I see it, but it cannot be even compiled because there is no such thing as StringWriter(String) wich I find completely irrational. So tell me, am I retarded or what? No, but seriosly, please help the newbie to understand these streams, am I supposed to use some kind of buffer? Any help appreciated.

    A String is an immutable. You cannot update a String.
    A new String() is basically the same as an empty String ""
    An empty StringWriter can be created with new StringWriter().
    If you use a BufferedReader you can call readLine().
    BufferedReader in = new BufferedReader(new FileReader(filename));
    String line;
    while((line = in.readLine()) != null) {
      System.out.println(line);
    }

  • Read Text file and count occurences of certain string

    Hello,
    I have a text file with lines of data in it. I would like to read this text file and count how many lines match a certain string of text. 
    For example my text file has this data in it.
    dog,blue,big
    dog,red,small
    dog,blue,big
    cat,blue,big
    If the certain string of text is "dog,blue,big" then the count would return "2".
    Thanks for your help

    Hello,
    Thank you for your post.
    I am afraid that the issue is out of support range of VS General Question forum which mainly discusses the usage issue of Visual Studio IDE such as
    WPF & SL designer, Visual Studio Guidance Automation Toolkit, Developer Documentation and Help System
    and Visual Studio Editor.
    I am moving your question to the moderator forum ("Where is the forum for..?"). The owner of the forum will direct you to a right forum.
    In addition, if you are working with Windows Forms app. please consult on Windows Forms Forum:http://social.msdn.microsoft.com/Forums/windows/en-US/home?category=windowsforms
    If you are working with WPF app, please consult on WPF forum:
    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=wpf
    If you are working with ASP.NET Web Application, I suggest that you can consult your issue on ASP.NET forum:
    http://forums.asp.net/
     for better solution and support.
    Visual Studio Language Forums:
    http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?category=vslanguages
    Best regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Read from xls file and put it in a table

    Hi,
    I've an xls file while is having 8 cells with some thousands of rows. i've to write a procedure to read that file and put it in a table(each cell as each column). pls help me how to proceed. i'm using oracle 9i
    Regards
    Abdul Muthalef

    as Gasparotto said, copy the csv file to the database server.
    create a directory object on the database.
    create directory dir_temp as 'e:\mydir'
    grant read, write on directory dir_Temp to <user>
    and then map this csv file to the external table using the below syntax.
    CREATE TABLE tab_hierarchy
    node_id          NUMBER,
    parent_id     NUMBER,
    description      VARCHAR2(255)
    ORGANIZATIOn EXTERNAL
         TYPE ORACLE_LOADER
         DEFAULT DIRECTORY dir_temp
         ACCESS PARAMETERS
         records delimited by newline
         fields terminated by ','
         (node_id,parent_id,description)
         LOCATION ('tree.csv')
    PARALLEL
    REJECT LIMIT UNLIMITED;in the above code, replace the filename under the LOCATION with your csv file name.
    now you should be just able to do select on this table and insert to the other main tbale.

  • How to display read file and put in ftp server in jsp

    Hi all
    since this is very importent question, please understand it and reply soon.
    i am using power analyzer sdk. front end as jsp.
    i want read a file using poweranalyzer sdk(how to read this?)and put it in ftp server(how to put this?)
    thanks and regards
    Kasim
    Bangalore

    http://java.sun.com/docs/books/tutorial/uiswing/components/editorpane.html

  • How to make an openfiledialog? (browse a file and put it in a parameter)

    How to make an openfiledialog? (browse a file and put it in a parameter)
    Best Regards

    hi,
    check the code  below:
    FORM sub_gui_download.
    * Define local variables
      DATA:
        lo_fullpath       TYPE string,
        lo_filename       TYPE string,
        lo_path           TYPE string,
        lo_user_action    TYPE i,
        lo_encoding       TYPE abap_encoding.
    * Define local constants
      CONSTANTS:
        lc_encoding(1) TYPE c VALUE 'X',
        lc_directory TYPE string VALUE 'D:',
        lc_filetype TYPE char10 VALUE 'DAT',
        lc_separator TYPE char01 VALUE 'X',
        lc_blank TYPE char01 VALUE ''.
    * Call method to create dynamic save_path and save_format
      CALL METHOD cl_gui_frontend_services=>file_save_dialog
        EXPORTING
          with_encoding        = lc_encoding
          initial_directory    = lc_directory
        CHANGING
          filename             = lo_filename
          path                 = lo_path
          fullpath             = lo_fullpath
          user_action          = lo_user_action
          file_encoding        = lo_encoding
        EXCEPTIONS
          cntl_error           = 1
          error_no_gui         = 2
          not_supported_by_gui = 3
          OTHERS               = 4.
      IF sy-subrc <> 0.
        EXIT.
      ENDIF.
    * Check user_action
      IF lo_user_action <> cl_gui_frontend_services=>action_ok.
        EXIT.
      ELSE.
    *   If user_action equals to action_ok, call function module to download datas
    *   using download table i_dwn_tab
        CALL FUNCTION 'GUI_DOWNLOAD'
          EXPORTING
            filename                = lo_fullpath
            filetype                = lc_filetype
            write_field_separator   = lc_separator
            trunc_trailing_blanks   = lc_blank
          TABLES
            data_tab                = i_dwn_tab
          EXCEPTIONS
            file_write_error        = 1
            no_batch                = 2
            gui_refuse_filetransfer = 3
            invalid_type            = 4
            no_authority            = 5
            unknown_error           = 6
            header_not_allowed      = 7
            separator_not_allowed   = 8
            filesize_not_allowed    = 9
            header_too_long         = 10
            dp_error_create         = 11
            dp_error_send           = 12
            dp_error_write          = 13
            unknown_dp_error        = 14
            access_denied           = 15
            dp_out_of_memory        = 16
            disk_full               = 17
            dp_timeout              = 18
            file_not_found          = 19
            dataprovider_exception  = 20
            control_flush_error     = 21
            OTHERS                  = 22.
        IF sy-subrc <> 0.
          MESSAGE i007.
        ENDIF.
      ENDIF.
    ENDFORM.    

  • I accidentally deleted all of my Logic Pro X files and put them in my trash but now that I copied them back to my documents they all play in the wrong places in my projects

    I accidentally deleted all of my Logic Pro X files and put them in my trash but now that I copied them back to my documents they all play in the wrong places in my projects

    Buddhaguru wrote:
    I know that Mac's don't have a roll back like PC's
    They do. It's called Time Machine.
    You need to reinstall all of your Apps. That should replace all of the support files you nuked.

  • When I open iPhoto 9.2.1 it says that my library needs to be upgraded but when I upgrade the library I am trying to open (33 GB worth of pictures from 2006) the new application says it cannot read the files and how to find them on the system to reimport?!

    When I open iPhoto 9.2.1 it says that my library needs to be upgraded but when I upgrade the library I am trying to open (33 GB worth of pictures from 2006) the new application says it cannot read the files and how to find them on the system to reimport?! and then I'd like to erase the original files since the space requirement is huge!!!! Why is upgrading software iPhoto such a pain. I've gotta get a presentation done and all I get for my money is roadblock!!!

    hello, it sounds like the library is damaged.
    Download iPhoto Library Manager and use its rebuild function. This will create a new library based on data in the albumdata.xml file. Not everything will be brought over - no slideshows, books or calendars, for instance - but it should get all your albums and keywords back.
    Because this process creates an entirely new library and leaves your old one untouched, it is non-destructive, and if you're not happy with the results you can simply return to your old one. 

  • How to read  *.pdf files and store them in a database?

    Dear programmers,
    I have problem with reading *.pdf files and store them in a database.
    can any one help me, please!
    Is it possible to read more than one file from the local system and store them in a database.
    thnaks in advance.
    bye

    What "problem" are you encountering?
    Depending on your choice of database software, it may or may not support the storage of binary large objects (BLOBs).

  • I am trying to import cr2files from the camera into lightroom 5 and keep getting an error message saying Lightroom can not read the files and therefore will not import them.  Has anyone had a similar problem-.thanks

    I am trying to import cr2files from the camera into lightroom 5 and keep getting an error message saying Lightroom can not read the files and therefore will not import them.  Has anyone had a similar problem….thanks

    If you are having the same problem, i.e. a disk permission problem, open your favorite search engine and search on, "change disk permissions", and I think you'll find plenty of information on how to fix the problem. This is a Lightroom forum. Your problem is with your operating system. There is no sense in rewriting instructions that are already available if you do a simple search.

  • After reinstalling CS6 the bridge photo downloader isn't able to read raw files and fails to convert the raw files to DNG. Previously downloaded raw files, now DNG, open up successfully in Camera Raw 7. How do I get the photo downloader to read and conver

    After reinstalling CS6 the bridge photo downloader isn't able to read raw files and fails to convert the raw files to DNG. Previously downloaded raw files, now DNG, open up successfully in Camera Raw 7. How do I get the photo downloader to read and convert raw files. MacBook Pro with Snow Leopard. No such problem before this reinstallation.

    You should install Camera Raw 4.6.
    Visit this page and follow the instructions carefully:
    PC:    http://www.adobe.com/support/downloads/detail.jsp?ftpID=4040
    Mac:  http://www.adobe.com/support/downloads/detail.jsp?ftpID=4039
    -Noel

  • Reading text file and output (to stdout) a list of the unique words in the

    Hi,
    I have a main method as
    main.java
    package se.tmp;
    public class Main
    public static void main( String[] args )
    WordAnalyzer.parse( args[0] );
    and text file as
    words.txt
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the quick brown fox jumps over the lazy dog
    the requirement is like
    I need create this WordAnalyzer class, implement the parse method, and then commit the file. This method takes a single parameter, the filename of the file to parse. The method should read this file and output (to stdout) a list of the unique words in the file along with the number of times each appears in the file.
    Can anyone please help me on this?
    Thanks.

    Where are you having problems?

  • Reading text file and display in the selectOnechoice list item In ADF.

    Hi,
    I have a requirement to read the text field which have list of strings and that string display in the SelectOneChoice List item component on page load.
    I am using Jdeveloper 11.1.2.3 version.
    Any suggestion will highly appreciated..
    Thanks in advance.
    Regards

    Hi,
    Google will produce you with hints on how to read content of a file from Java (ideally the file uses some delimiter). Then in a managed bean, you read the file and save its content in a list of SelectItem. So your managed bean should have the following property and setter/getter pairs
    ArrayList<SelectItem> listFromFile = new ArrayList<SelectItem>();
    public void setListFromFile(ArrayList l){ //you don't need this }
    public ArrayList<SelectItem> getListFromFile(){
       //read file content and iterate over the file list entries
      for(i=0, i < fileContent.length, ++i){
         SelectItem si = new SelectItem();
         si.setValue(... the value to update the list of value with ...);
         si.setLabel("... the label to show in the list ...");
         listFromFile.add(si);
      return listFromFile;
    }The af:selectOneChoice component should look as follows
    <af:selectOneChoice id=".." value="...attribute to update with selection ..." ...>
       <f:selectItems value="#{managedBean.listFromFile}"/>
    </af:selectOneChoice>Frank

  • How to make blank copies of a PDF file and put it into the printer tray.

    Dear experts,
    Before you try printing the data from the FM, How tomake several blank copies of the PDF file  and  put it in the printer tray so that you can print just the data from the function module on it??????
    Please reply.

    Hi drredwood,
    When you open your PDF file a yellow bar will appear on the top of the screen.
    Click on 'Enable All Features'.
    Then you will be able to copy the content from your pdf and to paste in any of the file.
    Regards,
    Florence

Maybe you are looking for