I can't read in a date from a txt file

Im not sure of the code needed to read in a date from the text file, this is an example of the text file:
1
2
2003
ie,
day
month year
I have to read in this date, this is the set method for the date:
public void setPurchaseDate (int d, int m, int y)
new Date(d,m,y);
And this is the code that I have tried using to readin the date:
  PurchaseDate=(Integer.parseInt(line),Integer.parseInt(line),Integer.parseInt(line));now i know its wrong, I just dont know what the code should be!!
Cheers

ok, I am going to go through it and see what values I can and cant read in, here is the code i am trying to use:
private void addx()
       FileReader fin;
       int noBooks;
       int itemNum;
       String title;
       String subject;
       double costNew;
       double costPaid;
       String isbn;
       double sellingPrice = 0;
       int noAuthors;
       int day;
       int month;
       int year;
        String seperator = "#";
        Book[] book = new Book[9];
        try
            fin = new FileReader("Books.txt");
            BufferedReader buff = new BufferedReader(fin);
            String line = buff.readLine();
            int count= 0;
            //read in Number of books
            noBooks=Integer.parseInt(line);
            while( line != null)
                //Read in item number
                itemNum = Integer.parseInt(line);
                //Read in title
                title = buff.readLine();
                //Read in number of authors
                noAuthors=Integer.parseInt(line);
                //Read each line in as an author until number of authors reached
                ArrayList authors = new ArrayList();
                for(int i=0; i < noAuthors ; i++)
                    authors.add(buff.readLine());
                //Read in cost new
                costNew = Double.parseDouble(line);
                //Read in subject
                subject = buff.readLine();
                //Read in ISBN
                isbn = buff.readLine();              
                //Read in purchase day
                day = Integer.parseInt(line);
                //Read in purchase month
                month=Integer.parseInt (line);
                //Read in purchase year
                year = Integer.parseInt (line);
                //Read in cost paid
                costPaid = Double.parseDouble(line);
                line = buff.readLine();
                //Pass date, month and year values to array
                Date purchaseDate =new Date(day,month,year);
                //Pass values to constructor
                if (line.equals(seperator))
                    book[count++] = new Book(itemNum, title, authors, subject, purchaseDate,costNew,costPaid,isbn, sellingPrice,noAuthors);
              // line = buff.readLine();
            System.out.println(book.toString());
        catch(Exception ex)
            System.out.println(ex.toString());
         }

Similar Messages

  • I have a VI and an attched .txt data file. Now I want to read the data from the .txt file and display it as an array in the front panel. But the result is not right. Any help?

    I have a VI and an attched .txt data file. Now I want to read the data from the .txt file and display it as an array in the front panel. But the result is not right. Any help?
    Attachments:
    try2.txt ‏2 KB
    read_array.vi ‏21 KB

    The problem is in the delimiters in your text file. By default, Read From Spreadsheet File.vi expects a tab delimited file. You can specify a delimiter (like a space), but Read From Spreadsheet File.vi has a problem with repeated delimiters: if you specify a single space as a delimiter and Read From Spreadsheet File.vi finds two spaces back-to-back, it stops reading that line. Your file (as I got it from your earlier post) is delimited by 4 spaces.
    Here are some of your choices to fix your problem.
    1. Change the source file to a tab delimited file. Your VI will then run as is.
    2. Change the source file to be delimited by a single space (rather than 4), then wire a string constant containing one space to the delimiter input of Read From Spreadsheet File.vi.
    3. Wire a string constant containing 4 spaces to the delimiter input of Read From Spreadsheet File.vi. Then your text file will run as is.
    Depending on where your text file comes from (see more comments below), I'd vote for choice 1: a tab delimited text file. It's the most common text output of spreadsheet programs.
    Comments for choices 1 and 2: Where does the text file come from? Is it automatically generated or manually generated? Will it be generated multiple times or just once? If it's manually generated or generated just once, you can use any text editor to change 4 spaces to a tab or to a single space. Note: if you want to change it to a tab delimited file, you can't enter a tab directly into a box in the search & replace dialog of many programs like notepad, but you can do a cut and paste. Before you start your search and replace (just in the text window of the editor), press tab. A tab character will be entered. Press Shift-LeftArrow (not Backspace) to highlight the tab character. Press Ctrl-X to cut the tab character. Start your search and replace (Ctrl-H in notepad in Windows 2000). Click into the Find What box. Enter four spaces. Click into the Replace With box. Press Ctrl-V to paste the tab character. And another thing: older versions of notepad don't have search and replace. Use any editor or word processor that does.

  • Populate a table reading the data from a TXT file

    how can I populate a table reading the data from a TXT file?
    thanks

    Hey Kevin!
    Using FORMS.TEXT_IO to bulk load data from a file strikes me as re-inventing the wheel. It is just about justifiable in a self-service environment, but I regard the EXTERNAL TABLE is a better solution for that situation as well.
    The same applies to UTL_FILE. I think the ability to read text with UTL_FILE is primarily intended for read file-based configuration or file manipulation/processing rather than data loading.
    Re-writing a text file into SQL statements is too much like hard work (even with an editor that supports macro definition and regular expressions) for no real benefit. You lose all the bulk load peformance you would get from SQL*Loader. But for QAD I'd probably let you off with it.
    You missed out one obvious alternative: using Java to turn the contents of an XML file into a CLOB and inserting it into a table which is read by a PL/SQL procedure that parses the XML records and insert the retrieved data into a table.
    Stay lucky, APC

  • What is the 'quickest' way to read char data from a txt file

    Hello,
    What is the 'quickest' way to read character data from a txt file stored on the phone to be displayed into the screen?
    Regards

    To be even a bit more constructive...
    Since J2me does not have a BufferedInputStream, it will help to implement it yourself. It's much faster since you read large blocks at ones in stread of seperate chars.
    something line this lets you read lines very fast:
      while ( bytesread < filesize ) {
             length = configfile.read( buff, 0, buff.length );
             // append buffer to temp String
             if ( length < buff.length ) {
                byte[]  buf  = new byte[length];
                System.arraycopy( buff, 0, buf, 0, length );
                tmp.append( new String( buf ) );
             } else {
                tmp.append( new String( buff ) );
             // look in tmp string for \r\n
             idx1 = tmp.toString().indexOf( "\r\n" );
             while ( idx1 >= 0 ) {
                //if found, split into line and rest of tmp
                line = tmp.toString().substring( 0, idx1 );
             /// ... do with it whatever you want ... ////
                tmp = new StringBuffer( tmp.toString().substring( idx1 + 2 ) );
                idx1 = tmp.toString().indexOf( "\r\n" );
             bytesread += length;
          }

  • How to skip footer details when loading data from a .txt file

    Hello experts,
    i have to import data from a txt file into my database. I have skipped my header info by using SKIP but how can i ignore my footer details.
    Thanks

    Reply on your other thread:
    Processing txt file for a required format

  • How can I read a specific character from a text file?

    Hi All!
    I would like to read a specific character from a text file, e.g. the 2012th character in a text file with 7034 characters.
    How can I do this?
    Thanks
    Johannes

    just use the skip(long) method of the input stream that reads the text file and skip over the desired number of bytes

  • Is it possible to insert data from a .txt file onto a form list?

    Hello everyone i have a question and really hope someone can help me out...
    I have made a form list in acces but now i want the option to insert data from a .txt automatically to that list in shaprepoint.. is this possible????
    * I forgot to say that i cannot use any third party software or powershell becauseof the limitations that i have in the comapny..

    If it's in Access, than you can consider linking this to your SharePoint List. I'm not sure what sort of options you'll have with just a text file.
    You might consider replacing that text file with an Excel Sheet and uploading it to the list with this Excel add-in
    http://www.microsoft.com/en-us/download/details.aspx?id=9345
    Steven Andrews
    SharePoint Business Analyst: LiveNation Entertainment
    Blog: baron72.wordpress.com
    Twitter: Follow @backpackerd00d
    My Wiki Articles:
    CodePlex Corner Series
    Please remember to mark your question as "answered" if this solves (or helps) your problem.

  • Reading Last line(record) from a txt file ina java

    Hi,
    I want to retrive the last line from a txt file.Can anybody help me??
    Thanx in advance

    In order to read the last line you must read all the lines before it. To read lines you can use the BufferedReader and LineNumberReader classes.
    Here's an example of how to read lines of text from a file:
    http://javaalmanac.com/egs/java.io/ReadLinesFromFile.html

  • How can I Read lines of data from a file starting at the end of the file??

    Can anyone help me with how to read lines of data starting from the end of a file instead of the beginning?? I do not want to load the entire file into memory as the files are very rather large. Instead I want to start at the end of the file and read lines backward , until I find the particular data item i am searching for, then stop.
    Can this be done in Java ? I know it can be done in Perl.
    Thanks.

    Thanks for your suggestion about the RandomAccessFile, I did actually thought about that approach , but wasn't sure it would work.
    I do not want to read the file in a sequential forward manner because the files contain large number of lines of data that have already been processed and therefore there is no need to reprocess these lines of data.
    The Unprocessed lines are always at the the end of the file and these are the data lines I am interesting in getting at without having to read the entire file. Therefore, i figure that if I can read the data from the end of the file then this would be much more efficient.

  • How can i read all the lines from a text file in specific places and use the data ?

    string[] lines = File.ReadAllLines(@"c:\wmiclasses\wmiclasses1.txt");
    for (int i = 0; i < lines.Length; i++)
    if (lines[i].StartsWith("ComboBox"))
    And this is how the text file content look like:
    ComboBox Name cmbxOption
    Classes Win32_1394Controller
    Classes Win32_1394ControllerDevice
    ComboBox Name cmbxStorage
    Classes Win32_LogicalFileSecuritySetting
    Classes Win32_TapeDrive
    What i need to do is some things:
    1. Each time the line start with ComboBox then to get only the ComboBox name from the line for example cmbxOption.
       Since i have already this ComboBoxes in my form1 designer i need to identify where the cmbxOption start and end and when the next ComboBox start cmbxStorage.
    2. To get all the lines of the current ComboBox for example this lines belong to cmbxOption:
    Classes Win32_1394Controller
    Classes Win32_1394ControllerDevice
    3. To create from each line a Key and Value for example from the line:
    Classes Win32_1394Controller
    Then the key will be Win32_1394Controller and the value will be only 1394Controller
    Then the second line key Win32_1394ControllerDevice and value only 1394ControllerDevice
    4. To add to the correct belonging ComboBox only the value 1394Controller.
    5. To make that when i select in the ComboBox for example in cmbxOption the item 1394Controller it will act like i selected Win32_1394Controller.
    For example in this event:
    private void cmbxOption_SelectedIndexChanged(object sender, EventArgs e)
    InsertInfo(cmbxOption.SelectedItem.ToString(), ref lstDisplayHardware, chkHardware.Checked);
    In need that the SelectedItem will be Win32_1394Controller but the user will see in the cmbxOption only 1394Controller without the Win32_
    This is the start of the method InsertInfo
    private void InsertInfo(string Key, ref ListView lst, bool DontInsertNull)
    That's why i need that the Key will be Win32_1394Controller but i want that the user will see in the ComboBox only 1394Controller without the Win32_

    Hello,
    Here is a running start on getting specific lines in the case lines starting with ComboBox. I took your data and placed it into a text file named TextFile1.txt in the bin\debug folder. Code below was done in
    a console app.
    using System;
    using System.IO;
    using System.Linq;
    namespace ConsoleApplication1
    internal class Program
    private static void Main(string[] args)
    var result =
    from T in File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TextFile1.txt"))
    .Select((line, index) => new { Line = line, Index = index })
    .Where((s) => s.Line.StartsWith("ComboBox"))
    select T
    ).ToList();
    if (result.Count > 0)
    foreach (var item in result)
    Console.WriteLine("Line: {0} Data: {1}", item.Index, item.Line);
    Console.ReadLine();
    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my webpage under my profile but do not reply to forum questions.

  • How to read data from a .txt file?

    currently i'm under study on java
    while need to extract data from a hyperterminal or .txt file
    could any one help me in this problem.?
    as in txt or .ht got their own overhead .( or what u call it. tt identify the file type)
    so how to open it and read data one ah?
    thanks all.

    Here's a code snippet 4 u
    String sInput = null;
    FileInputStream sStream = new FileInputStream("yourTxtFile");
    BufferedReader fileIn = new BufferedReader(new InputStreamReader(sStream));
    while((sInput = fileIn.readLine()) != null){
    System.out.println(sInput);
    hope this help
    *-)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to read data from a .txt file in real time

    Hi
    I am running a fortran code which takes around 1 week to run and output data are continuously saved in .txt files. I want to display these data and plot it against time in labview.
    Lets say I have a array of real numbers starting from 1.0 , and every 2-3 sec another number is added (output of code). So I dont want end-of-file-reached error in my program and also want program to wait until next data is updated in .txt file.
    I tried to make a simple read_txt_file.vi, but I am getting problems in terms of continous reading. Help !! Help !!
    Pl see the attached vi.
    Thanx
    PKJ
    Attachments:
    FileReader.vi ‏43 KB
    labview.txt ‏18 KB

    Hi PKJ,
          I modified your VI and it seems to do what you asked, that is, display the data from a file as the data is being added.
    Hope it helps!
    Message Edited by Dynamik on 11-08-2005 04:32 PM
    Message Edited by Dynamik on 11-08-2005 04:34 PM
    When they give imbeciles handicap-parking, I won't have so far to walk!
    Attachments:
    FileReader.vi ‏52 KB

  • Help! I want to read data from a txt file

    the data file is like this:
    b     a     v
    c     d     s
    c     c     d
    c     d     a
    c     c     c
    d     c     d
    c     c     c
    the total number of rows is big.
    How can I read it to an array without knowing the row number (array size)?
    Thanks.

    this is the part I finished.
    It will stop at 1000th line (I gave the initial array size 1000.)
    Is it because of this "for (int i=0; i<data.length; i++, k++) "
    so it stopped at the original size?
    import java.io.*;
    import java.util.*;
    public class test {
         private static void enlarge_array (String [][]data, int addsize) {
              String temp[][] = new String [data.length][data[0].length];
              System.arraycopy(data, 0, temp, 0, data.length);
              data = new String [data.length+addsize][data[0].length];
              System.arraycopy(temp, 0, data, 0, temp.length);
         public static void main (String args[]) throws IOException {
              int size = 1000;
              String data[][] = new String [size][4];
              BufferedReader br = new BufferedReader (new FileReader (args[0]));
              int k = 1;
              for (int i=0; i<data.length; i++, k++) {
                   StringTokenizer st = new StringTokenizer(br.readLine(), "     ");
                   for (int j=0; j<4; j++) {
                        data[i][j] = st.nextToken();
                   if (k==size) {
                        enlarge_array(data, size);
                        k=1;

  • How to update a table AUTOMATICALY with data from a .txt file??

    HI ,
    I want to upload data which is in a notepad file and Create a table. This notepad file stores a string of datas. Here, the data comes in to the .txt file every second.
    (The data is actually stored into the notepad file when a program is executed in Processing.js software)
    Is it possible to do the following using APEX ? ?
    1. This table has to be updated automatically once in 2 minutes (I want this completely automatic, no human intervention -- no update buttons)
    2. A report is to be created in a apex application with this table, it should reflect the updates in the table every 2 minutes.
    Is it possible?? give your ideas.. I want to do this soon for my engineering project :) Any help from you is appreciated. :)
    Edited by: user13301695 on 28-Mar-2011 10:09

    And how do you expect your database server to access a local file in your machine ?
    Is the file accessible from outside your machine say inside a webserver folder so that some DB process can poll on the file ?
    Or, is your DB server in the same machine where you have the text file ?
    You will have to figure out the file acess part before automating user interaction or even auto-refreshing.

  • Importing data from a .txt file and have Acrobat create new pages

    Hi everyone,
    I've created a form in Acrobat 9 to be used as an invoice. I want to be able to import data from an excel spreadsheet or .txt file into all the form fields. I know that I can go Forms > Manage form Data > Import Data to import 1 record at a time, but say I have about 50 invoices to populate, is there a way to import all the records at once and have acrobat create a new invoice for each of the customer's records?
    If there is a way, will it be compatible for Acrobat Reader users since this form will be used by someone who only has the Reader?
    Really appreciate any help.

    Sure.. this is what we use. "New Micro Right Click Tools"
    http://www.nowmicro.com/rct/

Maybe you are looking for

  • Server not starting after kernel upgrade

    Hi, I did a SAP Kernel upgrade of Patch 146 in NW2004s Unicode system After the kernel upgrade, the SAP is not starting Pls let me know of what can be teh reason The following is dev_disp file trc file: "dev_disp", trc level: 1, release: "700" sysno 

  • Issue while installing PHP

    I am getting following message while trying to install PHP4.4.2. Command: ./configure prefix=~/php with-apxs2=~/apache_2.2.2/bin/apxs with-config-file-path=~/apache_2.2.2/conf with-oci8=$ORACLE_HOME --enable-sigchild | *** ATTENTION *** | | | | Somet

  • Ipod touch 3rd gen iMessage sending/receiving delays

    I have been messaging my friend for a while and haven't had any known issues. Well yesterday an issue started occurring randomly. Messages will either not be received or sent. For instance: I'll send a message but it will never say it has been delive

  • How to create own customized screensaver on Windows 7 Embedded Standard sp1

    Hi Support,                   How to create own customized screensaver on Windows 7 Embedded Standard sp1 OS. Regards YASH PAL SINGH

  • How to delete all messages without reset iphone 4S

    Hello i want to delete all my mesasages in my phone without resetting data and other settings.