How to store the data of a file into an ArrayList?

Hi! everyone.
I want to know
if I have a File, and the data in the file are type int, type String...
And I have a ArrayList which is of type Question
How do I store the data of that file into the ArrayList
I tried to use the while loop(use the hasNextLine() to read the data line by line)
But I cannot add data which are not of type Question to the ArrayList.
Can you tell me what I should do, please?
I also wonder that
The data of the file are of many types, but when I try to read it with the nextLine(), the data all turn out to be of type String. Why?
Thank you.
Edited by: Terry001 on Apr 30, 2008 1:13 PM

No, a line in the file is just part of a question
The format of the file is like this:
*<question type code>                    :     String*
*<question point value>                    :     int*
*<question category>                         :     String*
*<question difficulty level>               :     int*
*<question text>                              :     String*
*<question correct answer>               :     String*
*<optional question-specific data>     :     String*
*<question terminator>                    :     String*
And here is an example
TF //TrueFalseQuestion
5 //points value
None //category
3 //difficulty level
The capital of the United States is Washington, D.C. //question text
True // answer
*** //quetion terminator
I created an ArrayList in the Test class:
private ArrayList<Question> questions; // Create inside constructor
    public Test (String name, String instr)
        testName = name;
        scoreEarned = 0;
        scorePossible = 0;
        instructions = instr;
        questions = new ArrayList<Question>(); //[MAX_NUMBER_OF_QUESTIONS];
    }And I tried to use the following method to store the data of the file to the ArrayList
// This method loads a set of questions from a plain text file
    public void loadQuestionsFromFile(String fileName) throws FileNotFoundException
        try
            File fileReader = new File("input.txt");
            Scanner sc = new Scanner(fileReader);
            while (sc.hasNextLine())
                // I don't know how to pass the data I got from the nextLine() method to the ArrayList because they are of different type
        catch (FileNotFoundException a)
            System.out.println(a);
    }    As all you said, I should create an Question object in the while loop
Question temp = new Question ();But I have no idea how to pass the int and String to the Question object.
Thank you

Similar Messages

  • How  to load the data from excel  file  into table in oracle using UTL_FI

    How to load the data from excel file into table in oracle
    and from table to excel file
    using UTL_FILE package
    Please give me some example

    This is something i tried in oracle apex
    http://avdeo.com/2008/05/21/uploading-excel-sheet-using-oracle-application-express-apex/
    Regards,
    CKLP

  • How to load the data from excel file into temprory table in Forms 11g?

    Hi
    How to Load the data from excel file(Extension is .CSV) into the temporary table of oracle in Forms11g.
    My Forms Version is - Forms [64 Bit] Version 11.1.2.0.0 (Production)
    Kindly Suggest the Solution.
    Regards,
    Sachin

    Declare
        v_full_filename         varchar2(500);
        v_server_path           varchar2(2000);
        v_separator             VARCHAR2(1);
        v_filename              VARCHAR2(400);
        filename                VARCHAR2 (100);
        v_stop_load             varchar2 (2000);
        v_rec_error_log         varchar2(4000);
        v_error_log             varchar2(4000);
        ctr                     NUMBER (12);
        cols                    NUMBER (2);
        btn                     number;
        RES                     BOOLEAN;   
        application             ole2.obj_type;
        workbooks               ole2.obj_type;
        workbook                ole2.obj_type;
        worksheets              ole2.obj_type;
        worksheet               ole2.obj_type;
        cell                    ole2.obj_type;
        cellType                ole2.OBJ_TYPE;
        args                    ole2.obj_type;
        PROCEDURE olearg
        IS
        args   ole2.obj_type;
        BEGIN
        args := ole2.create_arglist;
        ole2.add_arg (args, ctr);                                
        ole2.add_arg (args, cols);                                   
        cell := ole2.get_obj_property (worksheet, 'Cells', args);
        ole2.destroy_arglist (args);
        END;
    BEGIN
    v_full_filename := client_get_file_name(directory_name => null
                                     ,file_name      => null
                                     ,file_filter    => 'Excel  files (*.xls)|*.xls|'  
                                                                            ||'Excel  files (*.xlsx)|*.xlsx|'                                                                 
                                     ,message        => 'Choose Excel file'
                                     ,dialog_type    => null
                                     ,select_file    => null
    If v_full_filename is not null Then
    v_separator := WEBUTIL_CLIENTINFO.Get_file_Separator ;
    v_filename := v_separator||v_full_filename ;
    :LOAD_FILE_NAME := substr(v_filename,instr(v_filename,v_separator,-1) + 1);                                
    RES := Webutil_File_Transfer.Client_To_AS(v_full_filename,"server_path"||substr(v_filename,instr(v_filename,v_separator,-1) + 1));     
    --Begin load data from EXCEL
    BEGIN
        filename := v_server_path||substr(v_filename,instr(v_filename,v_separator,-1) + 1); -- to pick the file
        application := ole2.create_obj ('Excel.Application');
        ole2.set_property (application, 'Visible', 'false');
        workbooks := ole2.get_obj_property (application, 'Workbooks');
        args := ole2.create_arglist;
        ole2.add_arg (args, filename); -- file path and name
        workbook := ole2.get_obj_property(workbooks,'Open',args);
        ole2.destroy_arglist (args);
        args := ole2.create_arglist;
        ole2.add_arg (args, 'Sheet1');
        worksheet := ole2.get_obj_property (workbook, 'Worksheets', args);
        ole2.destroy_arglist (args);
        ctr := 2;                                                     --row number
        cols := 1;                                                -- column number
        go_block('xxx');
        FIRST_RECORD;  
        LOOP       
                --Column 1 VALUE --------------------------------------------------------------------
            olearg;
            v_stop_load := ole2.get_char_property (cell, 'Text'); --cell value of the argument
            :item1 := v_stop_load;
            cols := cols + 1;                                                      
              --Column 2 VALUE --------------------------------------------------------------------
            olearg;
            :item2 := ole2.get_char_property (cell, 'Text'); --cell value of the argument
            cols := cols + 1;
            --<and so on>
        ole2.invoke (application, 'Quit');
        ole2.RELEASE_OBJ (cell);
        ole2.RELEASE_OBJ (worksheet);
        ole2.RELEASE_OBJ (worksheets);
        ole2.RELEASE_OBJ (workbook);
        ole2.RELEASE_OBJ (workbooks);
        ole2.RELEASE_OBJ (application);
    END;
    --End load data from EXCELPlease mark it as answered if you helped.

  • How to store the data coming from visa into file

    Hi ,
    I want to store the data into text file,which is coming from visa-read.
    I tried visa read to file ,but it's not working.
     Am new to labview plz help me out.
    Thanks in advance. 

    CSFGF wrote:
    Hi ,
    I want to store the data into text file,which is coming from visa-read.
    I tried visa read to file ,but it's not working.
     Am new to labview plz help me out.
    Thanks in advance. 
     Share the code you have so far with us so that we can check what's going wrong.

  • How to display the data in XML files into JSP using Jdeveloper.

    Hi All,
    I have two XML files one XML file has the view names and the other has the table names of a particular views, how to display the data in JSP using JDeveloper where when i click a particular view the list of tables of that particular view from XML file two should be displayed in JSP Page.
    Are there any reference documents, regarding the above process please can anyone guide through how to do it.

    Let the servlet ask your business tier to provide the data, then stuff it into beans, and pack those into the Session instance. Then forward the request to the JSP, let the JSP get those beans and display them.

  • How to read the data from Excel file and Store in XML file using java

    Hi All,
    I got a problem with Excel file.
    My problem is how to read the data from Excel file and Store in XML file using java excel api.
    For getting the data from Excel file what are all the steps i need to follow to get the correct result.
    Any body can send me the code (with java code ,Excel sheet) to this mail id : [email protected]
    Thanks & Regards,
    Sreenu,
    [email protected],
    india,

    If you want someone to do your work, please have the courtesy to provide payment.
    http://www.rentacoder.com

  • How to store the datas in a .txt file in to a JTable in Java Swing

    Hi sir,
    Here i want to know how to store the data's of a .txt file
    in to a JTable in java swing.
    Where here the .txt file like for eg,spooler.txt is in the server and from there it will come to my client machine what i have to do is to take that .txt file and store the datas of the .txt file
    in a JTable.This is what i want.So pls. do help and provide the code as well.I will be thankful.Since i am involved in a project which involves this it is Urgent.
    Thanx,
    m.ananthu

    You can't just display data from a text file in a JTable. You have you understand the structure of the data so that you can parse the data and create a table model that can access the data in a row/column format. Here is an example of a simple program that does this:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=315172

  • How to Load the data from excel file(Extension is .CSV) into the temp.table

    Hi
    How to Load the data from excel file(Extension is .CSV) into the temporary table of oracle in Forms11g.
    My Forms Version is - Forms [64 Bit] Version 11.1.2.0.0 (Production)
    Kindly Suggest the Solution.
    Regards,
    Sachin

    Hello Sachin,
    You can use the following metalink note:How to Read Data from an EXCEL Spreadsheet into a Form Using Webutil Client_OLE2 (Doc ID 813535.1) and modify it a little bit.
    Instead of copy values into forms you can save them in your temporary table.
    Kind regards,
    Alex
    If someone's helpful or correct please mark it accordingly.

  • How to load the data from .csv file to oracle table???

    Hi,
    I am using oracle 10g , plsql developer. Can anyone help me in how to load the data from .csv file to oracle table. The table is already created with the required columns. The .csv file is having about 10lakh records. Is it possible to load 10lakh records. can any one please tell me how to proceed.
    Thanks in advance

    981145 wrote:
    Can you tell more about sql * loader??? how to know that utility is available for me or not??? I am using oracle 10g database and plsql developer???SQL*Loader is part of the Oracle client. If you have a developer installation you should normally have it on your client.
    the command is
    sqlldrType it and see if you have it installed.
    Have a look also at the FAQ link posted by Marwin.
    There are plenty of examples also on the web.
    Regards.
    Al

  • How to save the data of ABAP report into a notepad in desktop location???

    HI all,
    Can any one tell me how to transfer the data of ABAP report into a Notepad.
    Actually I have to schedule a ABAP report in background on daily basis and I want to transfer the
    whole record into Notepad.
    If any program is available for this..please clearify the relevent code for transferring.
    Thanks
    Rajeev

    declare a character type internal table.
    now move your data from it_data ( internal table with data ) into table itab.
    since you are running this report in background, you cannot save it to the desktop. Instead give any app server location
    data: itab(400) occurs 0 with header line.
    field-symbols: <fs1> type any.
    data: gv_file type rlgrap-filename default 'TEST.TXT'.
    data: gv_filepath type rlgrap-filename default <path>.
    LOOP AT it_data.
        DO 100 TIMES.
          ASSIGN COMPONENT sy-index OF STRUCTURE it_data TO <fs1>.
          IF sy-subrc = 0.
            CONCATENATE itab <fs1> INTO itab SEPARATED BY ' '.
          ELSE.
            EXIT.
          ENDIF.
        ENDDO.
        SHIFT itab LEFT DELETING LEADING ' '.
        APPEND itab.
        CLEAR itab.
      ENDLOOP.
      concatenate gv_filepath '/' gv_file into gv_file.
      OPEN DATASET gv_file FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
      IF sy-subrc = 0.
        LOOP AT itab.
          TRANSFER itab TO gv_file.
        ENDLOOP.
        CLOSE DATASET gv_file.
      ENDIF.

  • How to store the data coming from network analyser into a text or excel file

    Hii everyone
    I'm using Agilent 8719ET network analyser and wish to store the data coming from netowrk analyser into a text file/ excel file.
    Presently I'm able to get the data on Labview graph using GPIB . Can anyone suggest how to go ahead after collect data sub vi. How can the data be stored into a file apart from showing on the graph?
    Attached is the vi for kind consideration...
    Looking for help
    Regards
    Rohit
    Attachments:
    Agilent 87XX Series Exceed Max Meas.vi ‏43 KB

    First let me say that your code really looks pretty good. The data handling could be made more efficient by calculating the number of datapoints that are going to be in the completed dataset and preallocating the entire array -- but depending upon your answer to my questions, the logic in the lower shift register may be going away - so we won't worry about that right now.
    The thing I need to know before addressing the data storage question is: Each time you call "Collect and Display Data.vi", how many element are in the array? Are you reading single data points, or a group of data? (BTW: if the answer to that question is obvious based on the way the other VIs are setup, I don't have the drivers so I can't tell what the setup values are.) Second, how fast does the loop iterate? Are we talking msec per loop?, seconds? fortnights?
    The issues here are two-fold: how much data? and how fast is it coming? The answer to these will tell you how to save the data.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • How to store the data instead of memoryengine to database when use XML file

    Hi Experts,
    I have doubt which is into XML to database data transfer.
    While transferring the data from XML to database the tables will be store in memory for the xml files, my aim is instead of storing this in memory engine
    is there any way to store the data in to the data base itself..
    I am assuming when the data size increases say for example huge amount data, storing this much of data is big issue here right, so to avoid this is there any way to store
    this data directly in the database level.
    Please understand my requirement or else I have the good explanation about my requirement and please assist me how do this job....
    Thx,
    Sahadeva.

    Hi Experts,
    For this job I have applied the
    jdbc:snps:xmll?f=/mydata/xml/file.xml&s=wrk_admin&dp_driver=oracle.jdbc.driver.OracleDriver&dp_url=jdbc:oracle:thin:@localhost:1521:xel&dp_user=wrk_admin&dp_password=bPyXS2eRXw8fWnKEmTYSEf&dp_schema=wrk_admin&dp_doc=Y
    my schema name is wrk_admin
    xml file name is mydata
    jdbc driver: localhost:1521:xe
    Encoded password: I have encoded the pwd from cmd:c:oracle\oracle_odi1\oracledi\agent\bin\encode wrk_admin
    The above are the details I have applied to my ODI studio for creating the dataserver.
    After applying this I got the following error.
    Could you please correct me here if I am wrong...
    jdbc:snps:xml?param1=value1&param2=value2&...
         at oracle.odi.jdbc.datasource.LoginTimeoutDatasourceAdapter.doGetConnection(LoginTimeoutDatasourceAdapter.java:133)
         at oracle.odi.jdbc.datasource.LoginTimeoutDatasourceAdapter.getConnection(LoginTimeoutDatasourceAdapter.java:62)
         at com.sunopsis.sql.SnpsConnection.testConnection(SnpsConnection.java:1118)
         at com.sunopsis.graphical.dialog.SnpsDialogTestConnet.getLocalConnect(SnpsDialogTestConnet.java:420)
         at com.sunopsis.graphical.dialog.SnpsDialogTestConnet.localConnect(SnpsDialogTestConnet.java:860)
         at com.sunopsis.graphical.dialog.SnpsDialogTestConnet.jButtonTest_ActionPerformed(SnpsDialogTestConnet.java:806)
         at com.sunopsis.graphical.dialog.SnpsDialogTestConnet.connEtoC1(SnpsDialogTestConnet.java:165)
         at com.sunopsis.graphical.dialog.SnpsDialogTestConnet.access$1(SnpsDialogTestConnet.java:161)
    Thx,
    Sahadeva.

  • How to store the data?

    Hi,
    I'm new here, new to java
    I have a java polymorphism question here, I have three classes,
    Bicycle.java
    public class Bicycle {
    public void printClassName() {
    System.out.println("Bicycle");
    MountainBike.java
    public class MountainBike{
    public void printClassName() {
    System.out.println("MountainBike");
    TestBike.java
    public class TestBike {
    public ststic void main(String[] args) {
    String type = "MountainBike";
    Bicycle bike = new "type()";
    bike.printClassName();
    definitely, the type() is not correct here, is there any way to init the bike with a dynamic class without using switch/case?
    Thanks.
    peter

    thanks, everyone, I got it finally.
    actually, MountainBike is a subclass of Bicycle, I had a typo here,
    my code something like that using java reflection,
    TestBike.java
    public class TestBike {
    public ststic void main(String[] args) {
    String type = "MountainBike";
    CLass c = Class.forName(type);
    Method m = c.getDeclareMethod("printClassName", null);
    Object i = c.getnewInstance();
    Object r = m.invoke(i, null);
    I never used newInstance before, don't know the performance, because I may have lots of newInstance called.
    sorry for the misleading of subject, actually, I want to ask another question to store data,
    I had more than 40 files, I'd like to create a big xml to store the info of these files, like
    <A>
    <column>
    <name>AC1</name>
    <size>4</size>
    <name>AC2</name>
    <size>3</size>
    </column>
    </A>
    <A2>
    <column>
    <name>A2C1</name>
    <size>4</size>
    <name>A2C2</name>
    <size>3</size>
    </column>
    </A2>
    because A, A2 is not a constant, I don't know how to parse the xml file with java, or I create seperate xml file like
    A.xml
    <column>
    <name>AC1</name>
    <size>4</size>
    <name>AC2</name>
    <size>3</size>
    </column>
    any idea?
    Thanks.
    peter

  • How to read the data from a file in another computer with user name and password login

    How to read read the data from a file in anohter computer which need to login with user name and password?

    duplicate post:  http://forums.ni.com/t5/LabVIEW/log-on-the-other-computer-with-user-name-and-password/m-p/2061478
    duplicate post:  http://forums.ni.com/t5/LabVIEW/do-need-to-enter-the-user-name-and-password-when-TCP-ip/m-p/2061612
    duplicate post   http://forums.ni.com/t5/LabVIEW/log-on-the-other-computer-with-user-name-and-password/m-p/2060682

  • 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

Maybe you are looking for

  • Can I send an alert from iCal to a group in my contacts?

    First post so please go gentle. I have just set up an iCloud.com calendar and successfully synched to my iphone and ipad.  I have also set up so I can update contacts via iCloud.  All working great so far.  Anyway, I manage my son's football team and

  • Sql loader, how to get decimals into the database?

    oracle 10.2 we have data of the form 1.10 1.11 we are using "decimal external" in the control file. The table is a straight number field I did a test where I created a table with a number field and without and precision and did regular inserts. I got

  • Sound Brightness Contrast...

    Can anyone tell me why the sound, brightness and contrast keys don't always work? Sometimes it is just the sound that doesn't work. Other times it may be the contrast or brightness keys, or a combination of keys (two of the three keys). A couple of r

  • =?iso-8859-1?Q?Fort=E9_CGI_problem?=

    Messaggio a più sezioni in formato MIME. ------=_NextPart_000_008F_01BEFB9C.9ADF54B0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable We have encountered the following problem: Using the basic authentication

  • Question for scripting gurus: GREP search, change case make Smallcaps

    I have no knowledge of scripting at all, but this question keeps coming up during training sessions: is it possible to (java)script this: - Do a GREP search \u\u+ - Change case to lowercase - Apply SmallCaps (or: apply character style) this would all