Getting data from file to array

try
    System.out.println("Enter file name: ");
    fileName = Object.nextLine();
    BufferedReader inputStream =
            new BufferedReader(new FileReader(fileName));
    String employee = null;
    employee = inputStream.readLine();
    System.out.println("The first employee in " + fileName + " is");
    System.out.println(employee);
    inputStream.close();
catch(FileNotFoundException e)
    System.out.println("File " + fileName + " not found ");
catch(IOException e)
    System.out.println("Error reading from file " + fileName);
}This is just a little example I made. You can look at my other thread to see the other code. I need to put the data in a file into the array. Does it need to be casted somehow?

public void getData()
       try {
   System.out.println("Enter file name to read: ");
   File = Object.nextLine();
   BufferedReader Object =
            new BufferedReader(new FileReader(File));
    for(int i = 0; i < people.length && people[i] != null; i++)
String temp = Object.readLine();
people.setLastname(temp);
temp = Object.readLine();
people[i].setFirstname(temp);
temp = Object.readLine();
people[i].setID(temp);
temp = Object.readLine();
people[i].setPhone(temp);
temp = Object.readLine();
people[i].setYearlySalary(Double.parseDouble(temp));
temp = Object.readLine();
people[i].calcBonus(Double.parseDouble(temp));
temp = Object.readLine();
people[i].getMonthlyPay(temp));
} Object.close(); }I know, I got careless with the naming. I'm trying a different route now. I think I can just do it in reverse. lol How would I get the method getMonthlyPay to have no errors. It's a public void() method with monthlyPay = (yearlySalary + bonus) / 12; in its definition.
anyone?
Edited by: Program_1 on Dec 9, 2007 5:42 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Get data from file in server to client and vice versa

    after greeting
    i really didn't know how to use socket and serversocket to get data from file in the server and display it to client.
    also read file from client and save it to server.
    really i didn't know how to do it.
    really i want the reply as soon as possible

    You REALLY need to work through the Java networking tutorials:
    http://java.sun.com/docs/books/tutorial/networking/index.html

  • Tab Delimited data from file into array

    Could someone give me a full example of how to pull strings out of a text file and insert into an array. I have posted a couple of times and the segments of code that I get back isn't working. I don't know where I am going wrong exactly, so I would like to see a full example. Here is what I posted last.
    I don't want to use a loop. I want to specify what each array element is and how may there are before it is run.
    import java.util.StringTokenizer;
    import java.io.*;
    public class ReadDataFile
    public static void main(String args[])
    try
    FileReader fr = new FileReader("DataFile");
    BufferedReader br = new BufferedReader(fr);
    String s;
    String data[] = new String[12];
    int count = 0;
    while((s = br.readLine()) != null)
    StringTokenizer st =new StringTokenizer(s);
    data[0] = st.nextToken();
    data[1] = st.nextToken();
    data[2] = st.nextToken();
    data[3] = st.nextToken();
    data[4] = st.nextToken();
    data[5] = st.nextToken();
    data[6] = st.nextToken();
    data[7] = st.nextToken();
    data[8] = st.nextToken();
    data[9] = st.nextToken();
    data[10] = st.nextToken();
    data[11] = st.nextToken();
    data[12] = st.nextToken();
    System.out.println(data[3]);
    catch(IOException ioe)
    System.out.println(ioe.getMessage());
    With this I get this error when I try to run it.
    Exception in thread "main" java.util.NoSuchElementException
    at java.util.StringTokenizer.nextToken(StringTokenizer.java:235)
    at ReadDataFile.main(ReadADataFile.java:37)
    Thanks

    Just return String array instead of returning vector and change tokanizer according to ur requirement
    public Vector valuesarr(HttpServletRequest req, HttpServletResponse res,String user,String filename,String folder)
                        PrintWriter out =null;
                        boolean indbool=false;
                        boolean fd=false;
              try{
                             out = res.getWriter();
                        BufferedReader br =null;
                        String     fl=folder+"/txt/"+filename+".txt";
                        File tt = new File(fl);
                   String s, s2 = new String();
                        String userval;
                        String files;
                        int ind=0;
                        boolean indigo=true;
                        Vector v=new Vector();
                        if( tt.exists() )
                             String mainarr[]=null;
                             br = new BufferedReader(new FileReader(fl));
                                  while((s = br.readLine())!=null)
                                            s2=s+"\n";
                                            if (s.indexOf(user) > -1)
                                                 ind=s.indexOf(user);
                                                 StringTokenizer st = new StringTokenizer(s,";=");
                                                 String [] filearr1=new String[s.length()];
                                                 int t=0;
                                                      while(st.hasMoreTokens())
                                                           String stfiles1=st.nextToken();
                                                           filearr1[t]=stfiles1;
                                                           t++;
                                                 String filearr2 []=new String[t];
                                                      for( int a=0;a<t;a++)
                                                           if(filearr1[a]!=null)
                                                           v.addElement(filearr1[a]);          
         return v;
    }catch(FileNotFoundException f)
         out.println(f.getMessage());
         return null;
         catch(IOException io)
              out.println(io.getMessage());
              return null;

  • Should i use pipeline in order to get data from file path to create metadata?

    Hi,
    we use sharepoint 2013 to index file share and the folders structure represents data as project name / subject etc.
    Do you reccomend use pipeline capabilities in order to create metadata from those folders name? (so we will be able to use it as refiners later).
    In case so - how to do it?
    thanks
    keren tsur

    Hi  Keren,
    According to your description, my understanding is that you want to convert folder structure to SharePoint metadata.
    For achieving your demand, you can use the tool in codeplex:
    Folders To SharePoint Metadata Migrator (Folders2SP)
    Also you can have a look at the blog:
    http://en.community.dell.com/techcenter/sharepoint-for-all/w/wiki/5443.converting-folder-structure-to-sharepoint-metadata.aspx
    http://stackoverflow.com/questions/22411014/sharepoint-script-to-automatically-import-documents-from-a-network-share-on-a-r
    http://en.share-gate.com/blog/map-folder-names-to-sharepoint-metadata
    Best Regards,
    Eric
    Eric Tao
    TechNet Community Support

  • How to get data from file and save it in my DB

    Hi for all,
    my problem is :
    i have file in text format and this file have
    data .
    i want to insert this data into my database
    using forms .
    how i can do this .

    Hello,
    You can do this by :
    1. Command Host and u excecute SqlLoader
    Or
    2. Read the text file sequentially with text.io and insert data while not eof.
    Hope help u with this.
    null

  • How to get data from 2-D array?

    Some one help me with this....
    Attachments:
    quadrature decoder with digital signal as input.vi ‏172 KB

    you do logics on numbers - not a good idea. stick to boolean. I am not sure in LV, but in text based programming this often means checking for equal. If you compare integer to float numbers you are screwed.
    Replace your float 0 with a FALSE Boolean, dont cast your boolean array to integer.
    I dont really know what your program is ought to do, but you cannot wire an integer ARRAY into a non-array (case 1). Again, do not mix float with integer. I can see no reason why not to stick to booleans.
    At the end, you wired to non array result displays. use right click on the node and create --> indicator to avoid these errors in first place.
    Your while loop has no functionality by now but waiting for the stop button.
    Finally, please read the "how to post" of the forum and give a more detailed problem description. And maybe also read some of the "getting started with Labview" posts, I feel they might help you out a lot, especially datatypes and arrays should be a valuable readup.
    Edit: To answer your question of the subject - try out the "Index Array.vi"

  • Too big switch - get data from array

    I have text file (CSV). Parse file and set data to array, e.g. ArrayList. Get data from array and initialize object MyDoc (by setXXX methods)
         for (int index = 0; index < list.size(); index++) {
                   currentElement = list.get(index);
                   switch (index) {
                   case 0:
                        myDoc.setField1(currentElement);
                        break;
                   case 1:
                        myDoc.setField2(currentElement);
                        break;
                   case 70:
                        myDoc.setField70(currentElement);
                        break;OK. But problem is that object MyDoc have many fields (70 fields). And "switch" become to big. (70 setXXX methods). Can I set fields to object MyDoc without "switch"?

    johndjr wrote:
    Just don't use a switch. It is not really helping any in this case.
    you can just do all the calls explicitly.
    Like so
    myDoc.setField1(list.get(0));
    myDoc.setField2(list.get(1));
    myDoc.setField70(list.get(69));I might convert the list to an array first simply because it seems more natural to me.
    I'm not too sure if it really matters all that much if list is an ArrayList.
    String[] values = list.toArray();
    myDoc.setField1(values[0]);
    myDoc.setField2(values[1]);
    myDoc.setField70(values[69]);you should check that toArray() call, I might not have the correct method I'm kind of doing this off the cuff.I think it is second thoughts day.
    I don't like the hard coded numbers. what I wrote should have defined constants for those values.
    static final int FLD1 = 0;
    static final int FLD70 = 69;
    String[] values = list.toArray();
    myDoc.setField1(values[FLD1]);
    myDoc.setField2(values[FLD2]);
    myDoc.setField70(values[FLD70]);
    Edited by: johndjr on Apr 17, 2009 1:33 PM
    forgot the constants

  • Cant get data from text file to print into Jtable

    Instead of doing JDBC i am using text file as database. I cant get data from text file to print into JTable when i click find button. Goal is to find a record and print that record only, but for now i am trying to print all the records. Once i get that i will change my code to search desired record and print it. when i click the find button nothing happens. Can you please take a look at my code, dbTest() method. thanks.
    void dbTest() {
    DataInputStream dis = null;
    String dbRecord = null;
    String hold;
    try {
    File f = new File("customer.txt");
    FileInputStream fis = new FileInputStream(f);
    BufferedInputStream bis = new BufferedInputStream(fis);
    dis = new DataInputStream(bis);
    Vector dataVector = new Vector();
    Vector headVector = new Vector(2);
    Vector row = new Vector();
    // read the record of the text database
    while ( (dbRecord = dis.readLine()) != null) {
    StringTokenizer st = new StringTokenizer(dbRecord, ",");
    while (st.hasMoreTokens()) {
    row.addElement(st.nextToken());
    System.out.println("Inside nested loop: " + row);
    System.out.println("inside loop: " + row);
    dataVector.addElement(row);
    System.out.println("outside loop: " + row);
    headVector.addElement("Title");
    headVector.addElement("Type");
    dataTable = new JTable(dataVector, headVector);
    dataTableScrollPane.setViewportView(dataTable);
    } catch (IOException e) {
    // catch io errors from FileInputStream or readLine()
    System.out.println("Uh oh, got an IOException error!" + e.getMessage());
    } finally {
    // if the file opened okay, make sure we close it
    if (dis != null) {
    try {
    dis.close();
    } catch (IOException ioe) {
    } // end if
    } // end finally
    } // end dbTest

    Here's a thread that loads a text file into a JTable:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=315172
    And my reply in this thread shows how you can use a text file as a simple database:
    http://forum.java.sun.com/thread.jsp?forum=31&thread=342380

  • How to get data from a file?

    Hello everyone, i'm new to this forum and to java too. Ok, so here is what i want to do:
    I want to get data from a file containing words and numbers and store them into variables that i will use them after to insert into a database table. For example i have a file called employees.txt in this form:
    eid ename zipcode Hire_date
    1000 "Jones" 67226 "12-DEC-95"
    In C++ i declare variables for each data and store them, for example in this case:
    ifstream in("somefile");
    string name, hdate;
    int eid, zip;
    in >> eid >> ename >> zip >> hdate;
    So i want to do the same thing in JAVA but i can't make it work. So, i would appreciate if someone could give me a simple example how to do it. Thank you.

    [http://java.sun.com/docs/books/tutorial/essential/io/index.html]

  • Sending and getting data from external file.

    I'm running it in actionscript 1  and 2 since 3 wouldn't work when getting data from external media. I'm  trying to find out how to post data to a PHP file and getting from that  file I'm trying to make the flash for something that works like a game  but differently. Since I just found out how to make the HTML stuff show  up but a lot of times, some of my text will not appear so I don't know  what's going on.
    Does anyone know how to send and get data both at the same time from a sample file?
    The sample file is example.php
    It has to sent information like ID and NAME
    and it has to get information like Description and userID

    Ned Murphy wrote:
    The tutorial I pointed you to does provide the visuals you requested, both the AS code and sample PHP code, so I can't see where your learning by visuals aspect holds up.... your approach sounds more like you want someone to hand you a tailored solution that you won't need to learn from.  Visuals require reading and doing.  If that fails to get absorbed or you couldn't understand/revise it, what could anyone else prepare for you that would work better?
    I did the tutorial and everything but every time I press the button or even load it, it keeps on saying undefined. I like the have a sample FLA file so I can figure things out. I did everything from the site but it won't work out for me.
    I did step 5 too because it was almost all that I was looking for but it won't even work. keeps on saying undefined. I would show you but webcam max won't work and I can't show you an example.
    EDIT:
    You know it's frustrating when I don't know how the heck I'm supposed to do this stuff. I read the whole dang thing and I still can't get this dang thing working.
    I did everything. EVERYTHING. I just don't get this crap.

  • Is that possible to get data from the red trace in this BMP file

    I have an instrument, which only export image file. I want use labview to replot it and do some analysis. The image file is like attachment. Is that possible to get data from the red  trace in this BMP file via labview vis?
    Attachments:
    coax312.bmp ‏4741 KB

    I looks to me that 515 pixels represents 200 meters, so multiply the
    x-values by 0.3885 meters/pixel to get the true x-values.  I don't
    have enough information to scale the y-axis.
    Randall Pursley
    Attachments:
    Compute from BMP.vi ‏66 KB

  • How can i  get data from anather database system  ????????

    Hi every body..
    I 've a problem .....
    I've an old program work on "DOS" and it's content database which content all Data that i need for that program
    The data file extension with ".FD" , ".VW" , ".LSS" & "SLP"
    I want to kow:-
    1) what is that database system
    2)What program could open or can get data from that database tables.
    3)can i do that with oracle...
    please describe every thing in details...
    ... Please replay quickly... urgently
    ...waiting your answer....

    You're probably better off consulting the documentation for the DOS program you're trying to deal with than hoping someone here will be able to guess what program you're using, identify the structure of the files, and tell you how to extract the data into something Oracle can import.
    Justin

  • Trying to use FTP to get data from a different server

    Hi Friends,
        I have to use FTP to get data from a different server and upload it on SAP server. Now my problem is when I m trying to do ftp through command line it brings the file but with no data.
       Through ABAP program nothing is happening.
    Here's my code--
      V_PASSWORD = 'test@123'.
      V_PWD_LEN = STRLEN( V_PASSWORD ).
      CALL FUNCTION 'HTTP_SCRAMBLE'
        EXPORTING
          SOURCE      = V_PASSWORD
          SOURCELEN   = V_PWD_LEN
          KEY         = CS_KEY_500098
        IMPORTING
          DESTINATION = V_PASSWORD.
      CALL FUNCTION 'FTP_CONNECT'
        EXPORTING
          USER            = 'test'
          PASSWORD        = V_PASSWORD
          HOST            = '176.0.1.6'
          RFC_DESTINATION = 'SAPFTPA'
        IMPORTING
          HANDLE          = MI_HANDLE
        EXCEPTIONS
          NOT_CONNECTED   = 1
          OTHERS          = 2.
      CHECK SY-SUBRC = 0.
      cmd = 'lcd d:\ftp'. .
      PERFORM FTP_COMMAND USING CMD.
      CMD = 'asc'.
      PERFORM FTP_COMMAND USING CMD.
      CONCATENATE 'dir' 'ftpt*' INTO CMD SEPARATED BY SPACE.
      PERFORM FTP_COMMAND USING CMD.
      cmd = 'ls'.
    concatenate 'ls' INTO CMD SEPARATED BY SPACE.
      PERFORM FTP_COMMAND USING CMD.
      cmd = 'mget trial.txt'.
    CONCATENATE 'mget' 'trial.txt' INTO CMD SEPARATED BY SPACE.
      CALL FUNCTION 'FTP_COMMAND'
        EXPORTING
          HANDLE        = MI_HANDLE
          COMMAND       = CMD
        TABLES
          DATA          = MTAB_DATA1
        EXCEPTIONS
          TCPIP_ERROR   = 1
          COMMAND_ERROR = 2
          DATA_ERROR    = 3
          OTHERS        = 4.
      IF SY-SUBRC = 0.
        LOOP AT MTAB_DATA1.
          WRITE: / MTAB_DATA1.
        ENDLOOP.
      ELSE.
        CONCATENATE 'Error in FTP Command while executing' CMD INTO ERROR SEPARATED BY SPACE.
        WRITE: / ERROR.
      ENDIF.

    Hi
    try this.....in one of my reqt, i done this successfully....
    FORM FTPCON.
    FTP-------------------------------------------------------*
      CLEAR DSTLEN.
      SET EXTENDED CHECK OFF.
      DSTLEN = STRLEN( S_PWD ).     -
    >  (S_PWD (password) is a selection screen field )                  
      CALL FUNCTION 'HTTP_SCRAMBLE'
        EXPORTING
          SOURCE      = S_PWD
          SOURCELEN   = DSTLEN
          KEY         = KEY
        IMPORTING
          DESTINATION = S_PWD.
      CALL FUNCTION 'FTP_CONNECT'
        EXPORTING
          USER            = P_USER                   -
    > Username
          PASSWORD        = S_PWD             -
    > password
          HOST            = P_HOST                  -
    > Host
          RFC_DESTINATION = P_DEST         -
    > Destination
        IMPORTING
          HANDLE          = HDL
        EXCEPTIONS
          NOT_CONNECTED   = 1
          OTHERS          = 2.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CALL FUNCTION 'FTP_COMMAND'
        EXPORTING
          HANDLE        = HDL
          COMMAND       = 'set passive on'
        TABLES
          DATA          = RESULT
        EXCEPTIONS
          TCPIP_ERROR   = 1
          COMMAND_ERROR = 2
          DATA_ERROR    = 3.
      CALL FUNCTION 'FTP_R3_TO_SERVER'
        EXPORTING
          HANDLE         = HDL
          FNAME          = G_FCNAME
          CHARACTER_MODE = 'X'
        TABLES
          TEXT           = T_FILE1
        EXCEPTIONS
          TCPIP_ERROR    = 1
          COMMAND_ERROR  = 2
          DATA_ERROR     = 3
          OTHERS         = 4.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CALL FUNCTION 'FTP_R3_TO_SERVER'
        EXPORTING
          HANDLE         = HDL
          FNAME          = G_FCNAME1
          CHARACTER_MODE = 'X'
        TABLES
          TEXT           = T_FILE2
        EXCEPTIONS
          TCPIP_ERROR    = 1
          COMMAND_ERROR  = 2
          DATA_ERROR     = 3
          OTHERS         = 4.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CALL FUNCTION 'FTP_DISCONNECT'
        EXPORTING
          HANDLE = HDL.
      CALL FUNCTION 'RFC_CONNECTION_CLOSE'
          EXPORTING
            DESTINATION          = P_DEST
          EXCEPTIONS
            DESTINATION_NOT_OPEN = 1
            OTHERS               = 2.
        IF SY-SUBRC <> 0.
          MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
    ENDFORM.                    " FTPCON
    Hope it helps.....

  • How to get data from PDF form?

    PDF forms can send data in url like GET or POST method. Is it possible to get data from url, like in PHP http://sever/file.php?item1=value1&item2=value2&item3=value3
    In APEX url have specific construction and I don't know how to get value of items (1...3)
    Please let me help to find simple method of geting data from URL.
    Best Regards,
    Mark

    The APEX URL syntax is detailed here
    http://download.oracle.com/docs/cd/E14373_01/appdev.32/e11838/concept.htm#BCEDJBEH
    How to get it from PDF is another matter...
    I'm working on an app that downloads PDFs with a Large amount of data as a blob, takes that blob and changes it to XML, then goes through the xml to validate each section of data and then add it into the schema that my apex app is referencing....
    I didn't write the original code but I do know that it isn't a quick thing to implement and includes using some uploading some java jar files to your schema and writing some custom java code.
    Someone else may be able to help with grabbing PDF data into the URL for the amounts of data you want to pass to apex.
    Gus..
    REWARDS: Please remember to mark helpful or correct posts on the forum, not just for my answers but for everyone!
    Edited by: Gussay on Sep 21, 2009 5:52 PM

  • Need to Get Data From Siebel On Demand ( I am new to Siebel Please Help)

    Hi All,
    I have a project in which i need to get data from Siebel On Demand and Automate this process.
    I have downloaded the Custom WSDL file and the Schema file from Oracle Siebel On Demand. I am using IDE WSAD and when i import these files into WSAD i am getting an error stating the schema definitions are wrong. Can anyone help me.....
    I need to complete it asap....
    Edited by: user491578 on Nov 11, 2008 6:50 PM

    You should probably ask Advantech. This question really has nothing to do with LabVIEW SE or NI-ELVIS. You could try posting to the LabVIEW board but there have only ever been two posts regarding 'advantech 4716'.

Maybe you are looking for