How to save the time to a .txt file and retrive it back as time?

I have to save the time [hour:minute:second] and the date [date:month:year] to a .txt file. I am using the Calendar API to set the time and date as below
FileOutputStream fileStream = new FileOutputStream ("what.txt");
PrintWriter pw=new PrintWriter(fileStream, true);
Calendar curDate = Calendar.getInstance();
System.out.print(curDate.get(Calendar.DATE)+":");
System.out.print(months[curDate.get(Calendar.MONTH)]+":");
System.out.print(curDate.get(Calendar.YEAR));
pw.println(curDate);
I'll have to retrive these data back to use it to set timer
timer = new Timer();
timer.schedule(new RemindTask(), time);
I try to retrive the data and use the Calendar API to that data by using the below program.
I get the error as :
C:\t\Retrivedate.java:41: int cannot be dereferenced
System.out.print(t.get(Calendar.DATE)+":");
How can I solve this so that I can use Calendar API on my retrived data?
import java.io.*;
import java.util.*;
import java.lang.*;
class Test {
public static void main(String args[]) {
try {
File inputFile = new File("what.txt");
FileReader in = new FileReader("what.txt");
int t;
char[] tmp = new char[100];
int cnt = in.read(tmp);
String tm="";
for (int j=0;j<cnt;j++)
{ tm+=tmp[j];
try {
t=Integer.parseInt(tm,10);
catch (NumberFormatException exception) {}
System.out.println("jika "+tm);
Calendar curDate = Calendar.getInstance();
String months[]={
"Jan","Feb","Mar","Apr",
"May","June","July","Aug",
"Sept","Oct","Nov","Dec"};
Date time1 = curDate.getTime();
System.out.print(" \n"+time1.getHours());
System.out.print(":"+time1.getMinutes());
System.out.println(":"+time1.getSeconds());
System.out.print(t.get(Calendar.DATE)+":");
System.out.print(months[t.get(Calendar.MONTH)]+":");
System.out.print(t.get(Calendar.YEAR));
in.close(); }
catch (IOException ex) {
System.out.println("IOException:"+ex.toString()); }

These lines do not make sense:
System.out.print(t.get(Calendar.DATE)+":");
System.out.print(months[t.get(Calendar.MONTH)]+":");
System.out.print(t.get(Calendar.YEAR));
1. t is an integer, it does not have any methods.
2. It's a bad idea to use char[] to retrive the date. You should use readLine() method to retrieve the whole date string, say "10/23/2001" (certainly you can have hours, minutes, seconds, etc.). Then you need to use SimpleDateFormat class to parse this string. SimpleDateFormat gives you everything to parse a date string in any format you want.
PC

Similar Messages

  • How to get the content in embed swf file in Swf Loader on run time

    How to get the content in embed swf file in Swf Loader on run time
    [Bindable]
    [Embed(source="assets/index.swf")]
       private var SWFSRC:Class;
    <mx:SWFLoader id="_swfloader" source="{SWFSRC}" />

    Hi Flex harUI,
    Throw the error.
    Access of undefined property content

  • How can i open a DOC or TXT file and insert the data into table?

    How can i open a DOC or TXT file and insert the data into table?
    I have a doc file . the doc include some columns and some rows.(for example 'ID,Name,Date,...').
    I'd like open DOC file and I'd like insert them into the table with same columns.
    Thanks.

    Use the SQL*Loader utility or the UTL_FILE package.

  • How to save the audio bytes in a file

    I am capturing the audio from microphone.I write the audio data as bytes to other clients.How can i save the bytes in a wav file and it can be played in future?Please help.I want to write the audio bytes in a wav file

    get sample source code from
    http://javasolution.blogspot.com/2007/04/record-and-save-audio-using-java.html

  • How to search a special string in txt file and return it's position in txt file?

    How to search a special string in txt file and return it's position in txt file?

    I just posted a solution for a similar question here:  http://forums.ni.com/ni/board/message?board.id=170​&view=by_date_ascending&message.id=362699#M362699
    The top portion can search for the location of a string, while the bottom portion is to locate the position of a character.  Both can search for a character.
    The position of the character within the file is displayed in the indicator(s).
    R

  • How to save the RichTextBox Content in Text file

    hI ,
    I NEED TO SAVE THE RichTextBox Content in text file ? 

    If this IS a LabVIEW question, here's an example of how to load a rich text file (to help if you don't know how to get a rich text in LabVIEW).
    If you have a Rich Text Box, you can use the invoke method "SaveFile" to match the function you linked to.

  • How to read the data in a txt file on a web site?

    I want to extract the numbers located in txt files on a web site. It's a normal url. Not a ftp.
    Does anyone know how to do it?

    Hi Tom,
    What do you want to extract from the text file??
    I wanted to extract an IP address from a pearl script from my FTP server and this was the vi that I used .I dont know if you are trying to do the same?
    Here is the vi.It is in LV 7.1
    Hope its helps .
    Good luck.
    ohiofudu.
    Certified LabVIEW Architect
    Certified TestStand Developer
    Attachments:
    PublicIP-Adresse.vi ‏31 KB

  • 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 type the question in a .txt file

    im trying to create a java game like hangman if you heard of it. i noe that all the questions are needed to be type in a .txt file but i not sure how should it be type or in wad format. is there anyone out there who can help me with it? thank u

    You can type the questions on diffrent lines. Then using io you can use the InputStream.readLine() function to get each question individually.
    Why dont you try using JDBC for the same?
    http://www.thejavahub.com - Java Applications, Applets, Servlets, Code, Tutorial, Jobs, Articles and more. Register Now.

  • How to save the visual settings   in css file ?

    hi all,
    I have designed a chart using java and ilog API, and i am applying the visual setting from .css file. But i have some option in GUI to change the visual settings. For ex: background color,leged text syle etc. I should provide one button to save the existing visual settings of the graph in .css. ( It may replace or edit the existing .css file. Please help me out regarding this.
    thanks in advance
    Mohanraj.K

    We can use the css file to apply the styles to chart... We have some readymade API it does that. It not only for HMTL. So when we run our application first time it will read the .css file and apply the properties. For example The background color in .css file is green. When we run the application first time it will apply green color to the chart background. Then i have some API it changes the chart background as user wants. for ex : red. When i close the application the i have to replace the .css background value as red from green. And we have to save the changed .css. My Q is very much unambiguous..
    please help me out
    Mohanraj.K

  • How to read the contents of a text file and populate the data in a table ?

    Hello All,
      Can anyone advise on how to acheieve the above ? I am trying to read in a text file (CSV) and have the contents populated to the respective UI elements in a table. Any help is greatly appreciated.
    from
    Kwok Wei

    Hi,
    Let us consider you have list of names(Seperated by delimeter) in a text file and you want to display in  a table.
    1. Create Context Node "Names" and context attribute "Name"
    2. Create Table and bind to the above context.
    3.Write the following code in the "Init method.
    try{
    FileReader f =new FileReader("");
    BufferedReader r=new BufferedReader(f);
    String names=r.readLine();
    Vector Names=new Vector();
    // Use Tokenizer and store all the names i a vector//
    for(int i=0;i<Names.size();i++){
    IPrivate<<VieName>>.INameElement ele=wdContext.createNameElement();
    ele.set<<Name>>( Names.get(i).toString());
    wdContext.NodeName().addElement(ele);
    Regards, Anilkumar
    Message was edited by: Anilkumar Vippagunta

  • How to save report output in a PDF file and also show preview in one processing cycle

    Hi every body,
    We R re-developing an application from COBOL to Oracle.
    Using Reports 6i 6.0.8.11.3.
    The requirement is that whenever a user processes a report, it should be saved on disk say in PDF format. Then it should be shown in Reports Runtime Previewer.
    So far I have explored that only one of theses can be done in one processing cycle.
    That is if we set DESTYPE to FILe it will only be saved to disk. If we set DESTYPE to Preview, the report can be previewed and optionally printed but not saved.
    I want that both saving to disk and preview should be possible.
    I have explored .DST file option but there is only provision for FILE, PRINTER and MAIL.
    Printing facility should be optional, otherwise we would have used FILE and PRINTER destinations in .DST file.
    Once that file is saved on disk, it can later on be printer if user requires more copies.
    I would prefer a solution other than User_exit as I don't have training in developing user_exits.
    Any help please.
    Tariq

    I had a similar requirement and decided to run the report from forms. When a button is pressed, the report is run to create the pdf file, followed by separate command to invoke acrobat reader or internet explorer to display the file, rather than using reports previewer.
    The file can be displayed from forms by a host command in client server, or by web.show_document on the web.

  • How to change the layout of an input file and write to an output file

    Hi
    I have a .csv file which has a layout as schoolNo. , county1,county2,county3,county4,county5
    It will need to go into an output file as schoolNo. repeated and a county on each record .
    ie., schoolNo.,county1
    schoolNo.,county2
    schoolNo.,county3
    schoolNo.,county4
    schoolNo.,county5
    I wrote the java program as follows ..which results in this error
    Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
    BECAUSE :--
    i know bec., the first record doesnot have county3,county4,county5 . So when the if loop for county3 lenght is checked it gives this exception .
    Pls help me write this program ..thanks in advance .
    /Here I open the input file and read in record by record                                                                                                                        
              BufferedReader readin;
              try {
                   readin = new BufferedReader(new FileReader(InFile));
                   String firstLine = readin.readLine();
                   String[] headers = firstLine.split(",");
                   columnCount = headers.length;
                   System.out.println("Columns in ZIP Master File: "+columnCount);
                   for(String input ;(input = readin.readLine()) != null; ){
                        recCount++;
                        input = input.substring(1);               
                        String[] column = input.split(",");
                        if(columnCount == 10){
                             eachIP++;
    //                               OUTPUT FILE
                                    if(column[1].length()> 0) {
                                       String mainStr = column[0] + "," + column[1] ; 
                                       Count++;
                                       totalcolumns++;
                                       writeOutFile.write(mainStr);
                                       writeOutFile.newLine();
                                  else{
                                  bypassedCount++;
                                    if(column[2].length()>0){
                                         String mainStr = column[0]+ "," + column[2];
                                         Count++;
                                         totalcolumns++;
                                       writeOutFile.write(mainStr);
                                       writeOutFile.newLine();
                                  else{
                                  bypassedCount++;
                                    if(column[3]..length()>0){
                                         String mainStr = column[0]+ "," + column[3];
                                         Count++;
                                         totalcolumns++;
                                       writeOutFile.write(mainStr);
                                       writeOutFile.newLine();
                                  else{
                                  bypassedCount++;
                                 }

    There are two split( ... ) methods; check the other one (the one with two arguments), it allows for empty entries to be counted, i.e. split(inputString, -1) gives you the wanted results.

  • How to save a 4D Array in a File and load it later on?

    Hello,
    I am trying to save a 4D Array (Array[4000] [3] [20] [5]) of UINT in a File. I can do it through "write in binary File". But then I can´t load it. I know I can transform my Array down to 1D Array of 1.200.000 Elements (4000*3*20*5) of UINT. When I load it, I have to transform it back (with a lot of "for-looping") back to 4D. But is there an easier way of doing that?
    I was not able to find a solution in this forum - I am sorry if I made a new thread if there is already a solution in this forum.
    Best regards
    LabVIEW 2011
    Solved!
    Go to Solution.

    As Lynn said, there should be no extra code required.
    When writing, make sure that "prepend size" is true (true is default) and when reading, wire an empty 4D array of the correct representation to the "data type" input.
    (I also assume that your LabVIEW version is not extremely ancient)
    LabVIEW Champion . Do more with less code and in less time .

  • How to skip certain lines for a txt file and insert into array

    so here is my question:
    i had a file to read, and it requires to input into the array starting from a certain line
    example:
    4
    john 25 M
    mary 22 F
    lee 20 M
    faye 10 F
    faye john
    mary john
    mary faye
    i want to insert the friend list, starting 5th line into a 2d array, which is the int from first line +1.
    can someone help me with it?
    i believe there is a skip method and stuff..
    but just dont know how to use it
    may someone tell me how to do tat?

    the thing is i think that takes too long and it is not efficient..
    however...i just solved it with a better method
    Scanner in = new Scanner (reader);
    int size = Integer.parseInt(in.next());
    BufferedReader insert = new BufferedReader(new FileReader(new File(input)));
    String line = null;
    int count = 0;
    int startAtLineNo =size+1; // 0-based
    while ((line = insert.readLine()) != null) {
    if (count >= startAtLineNo) {
    /* do stuff */
    System.out.println(line);
    // else ignore
    count++;
    thanks anyways

Maybe you are looking for

  • Acrobat 9 Pro / Files with public+private key security

    Hi, I'm working at a Software Company. We want to create the Help Documents for our Software in PDF. We want to take care, that those PDF documents cannot be opened without our Software. My idea is to certificate the PDFs with a public key and the pr

  • Connecting with external time recording system

    Hi,  I need to know how an in-house Java Time Recordins System can communicate with SAP.  The plan is for this system to send raw data, clock in, clock out to SAP work schedules.  Employees are mostly positive and have occasionnaly shift differential

  • Sending mail to invalid mail address but domain valid.im not getting any NDR

    Hi, In my organisation I'm sending mail to invalid email address but domain is valid ...i'm not getting any NDR. I want NDR like this  The e-mail address you entered couldn't be found. Please check the recipient's e-mail address and try to resend the

  • TNS_ADMIN (path to tnsnames.ora) using Instant Client IGNORED

    Hi, I developed a simple utility which uses OCCI LIB from 10g release. I'm deploying it with Oracle Instant Client lite libraries. Everything works fine when tnsnames.ora is present in the same dir. When I move it somewhere else and set TNS_ADMIN to

  • Program in my Startup

    Hi Guys I installed a couple of programs this evening and now it starts when i login. I cant figure out how to delete it and stop it. Its no longer in the Applications folder. Any ideas? Thanks!