• Post Reply Bookmark Topic Watch Topic
  • New Topic

how do I create a new File in order to write info

 
john mattucci
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I write to a file (ie: a non existing file) for eg. the user will input todays total sales thus a new file will need to be created with todays date; prior to java 1.2 since I cannot use
such methods as createNewFile()
Thank u for your help.
 
Mazhar Shaikh
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there,
you probably will have to use the following lines of code,i guess
--------
String today = new Date();
FileOutputStream ostream = new FileOutputStream("today");
ObjectOutputStream p = new ObjectOutputStream(ostream);
p.writeObject(your figure);
.
.
--------
i hope this is what you are expecting
 
guy ranch
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here u go:
import java.io.*;
import java.util.*;
public class update
{
public static void main(String args[]) throws IOException
{ File f=new File("c:/update.txt");
String today=(new Date()).toString();
FileWriter fw=new FileWriter(f);
fw.write(today);
fw.close();
}
}
p.s. the Date() constructor is i suppose deprecated but i dont know the new version.

[This message has been edited by guy ranch (edited May 19, 2001).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!