• Post Reply Bookmark Topic Watch Topic
  • New Topic

i\o streams  RSS feed

 
Tersa
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
int hours = 1
String report = "report"
double time = 3.50
can someone please help me with this, having lotz of trouble!!Arghh :-)...i would like to create a file that contains the info from hours, report and time. Then I would like to output the info from this file onto the terminal screen afterwards. How would I do this?? (It would be great if you could provide me with the code) Thanks a lot! Really appreciate your help!!
The output should be
1 report 3.50
 
SaSaS
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check this out.
-----------------
import java.io.*;
class Print2File{
final String FILENAME="Default.dat";
BufferedReader readData=null;
PrintWriter write2File=null;
int hour=0;
String report="",strFileName="",readLine="";
double time=0.0;
public Print2File()throws Exception{
readData=new BufferedReader(new InputStreamReader(System.in));
System.out.print("\nPlz Enter the Hour-->");
hour=Integer.parseInt(readData.readLine());
System.out.print("Plz Enter Report Name-->");
report=readData.readLine();
System.out.print("Plz Enter the time-->");
time=Double.parseDouble(readData.readLine());
System.out.print("\n\nPlz Enter The File Name [[Defaulted To Default.dat]] -->");
strFileName=readData.readLine();
if(strFileName==null || strFileName.equals(""))
strFileName=FILENAME;
write2File=new PrintWriter(new FileOutputStream(strFileName,true),true);
write2File.println(hour+"\t"+report+"\t"+time);
System.out.println("Reading Data From File");
readData=new BufferedReader(new InputStreamReader(new FileInputStream(strFileName)));
System.out.println("\nHour\tReport\tTime\n");
while((readLine=readData.readLine())!=null){
System.out.println(readLine);
}
}
public static void main(String args[])throws Exception{
new Print2File();
}
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!