The Artima Developer Community
Sponsored Link

Java Answers Forum
HELP: read in a line and stores it in another file

2 replies on 1 page. Most recent reply: Apr 28, 2003 2:47 AM by higenyi

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
jarvis

Posts: 1
Nickname: jarvis
Registered: Apr, 2003

HELP: read in a line and stores it in another file Posted: Apr 27, 2003 7:39 AM
Reply to this message Reply
Advertisement
hello,

I?m an absolute newbe in programming java, and so I hope someone would be so kind and help me with the following question.

I want to write a java program, that reads in a line of another file and stores it in a new file. In the following source code, the file reads in a whole text from an file and stores it in another file, BUT what do I have to do if I only want to filter some words and store them?

import java.io.*;
import java.util.Date;




public class readIn {
public static void main(String[] args) throws IOException {



for (int i = 1; i <= 5; ++i) {
System.out.println("Sleep at: " + new Date());
try
{

Thread.sleep(500);
}
catch(InterruptedException e)
{
System.out.println("Sleep interrupted:"+e);
}
File inputFile = new File("example.txt");
File outputFile = new File("out.txt");

FileReader in = new FileReader(inputFile);
FileWriter out = new FileWriter(outputFile);
int c;


while ((c = in.read()) != -1)
out.write(c);

in.close();
out.close();


System.out.println("Awoke at: " + new Date());
}
}
}











THANK YOU VERY MUCH for an immediate answer!!!


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: HELP: read in a line and stores it in another file Posted: Apr 27, 2003 5:50 PM
Reply to this message Reply
Wrap your Reader in a BufferedReader, then you'll be able to read a line at a time, with readLine().

higenyi

Posts: 1
Nickname: thigenyi
Registered: Apr, 2003

Re: HELP: read in a line and stores it in another file Posted: Apr 28, 2003 2:47 AM
Reply to this message Reply
hullo
questions to hilly@arnold2k.zzn.com

Flat View: This topic has 2 replies on 1 page
Topic: Version Previous Topic   Next Topic Topic: Making Events work from different classes

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use