• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error while writing to a file

 
abhinav sinha
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.

------------------------------------------------------------------
<code>

package Sample;

import java.util.*;
import java.io.*;
public class MediocreExecJavac
{
public static void main(String args[])
{
try
{
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;
System.out.println("<ERROR>");
while ( (line = br.readLine()) != null)
System.out.println(line);
fw.write(line);
System.out.println("</ERROR>");
int exitVal = proc.waitFor();
System.out.println("Process exitValue: " + exitVal);
fw.close();
} catch (Throwable t)
{
t.printStackTrace();
}
}
}

<\code>
----------------------------------------------------------------------

Below is the output -

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


-----------------------------------------------------------------------

Please tell where the program is going wrong.
 
abhinav sinha
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
aahh..I am sorry guys.I found my mistake.Now my program is running fine.
:-)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic