Below is the is another program on streams.
[+/-] show/hide
/*reading from a file*/
import java.io.*;
public class ReadFromFile{
public static void main (String[] args) throws IOException{
InputStream istream;
OutputStream ostream;
int c;
File inFile=new File("\\Documents and Settings\\Rose\\My Documents\\NetBeansProjects\\SampleExercises\\src\\data.txt");
File outFile=new File("\\Documents and Settings\\Rose\\My Documents\\NetBeansProjects\\SampleExercises\\src\\output.txt");
istream= new FileInputStream(inFile);
ostream=new FileOutputStream(outFile);
try{
while ((c=istream.read()) != -1){
ostream.write (c);
}
}catch (IOException e)
{System.out.println("Error :"+e.getMessage());}
finally {
istream.close();
ostream.close(); }
}
}
No comments:
Post a Comment