wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes error while writing to a file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "error while writing to a file" Watch "error while writing to a file" New topic

error while writing to a file

abhinav sinha

Joined: Nov 29, 2007
Posts: 22

I am getting an error while writing to a file.Here is the sample code in which I am getting error.The STDERR is getting printed to console but the same is not getting written to a file.


package Sample;

import java.util.*;
import java.io.*;
public class MediocreExecJavac
public static void main(String args[])
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("perl ic_start");
InputStream stderr = proc.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
FileWriter fw=new FileWriter("result.txt");
String line = null;
while ( (line = br.readLine()) != null)
int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
} catch (Throwable t)


Below is the output -

Can't open perl script "ic_start": No such file or directory
at java.io.Writer.write(Unknown Source)
at Sample.MediocreExecJavac.main(MediocreExecJavac.java:21)


Please tell where the program is going wrong.
abhinav sinha

Joined: Nov 29, 2007
Posts: 22
aahh..I am sorry guys.I found my mistake.Now my program is running fine.
I agree. Here's the link: http://aspose.com/file-tools
subject: error while writing to a file