sory but i could not understand what you want.
do you want to write to a file instead of printing to screen?
if so, you should use someting RandomAccessFile
import java.io.*;
public class Test
{
public static void main(String[] args) throws IOEXception
{
RandomAccessFile file=new
RandomAccessFile("c:/file.txt","rw");
//know use
file.writeBytes("what ever you want to write to the file");
//instead of
System.out.println("the string you want to write");
}
}
The seems correct but I have try that many times but that pipe will not work when trying to compile using javac
EtcJavac name.java > error.txt
will not work( but that how u do it in dos)
with you go check the txt file their nothing their
I'm still trying to find a way of doing it so it can be eaiser to debug my program.
you can try this it works in unix and I think it is the same for winbloze also:
java YourProgramName > outfile.txt
I'm not sure but I was told that it would work.
just like the dos "type" command the System.out.println
method writes to the standard output.
Sorry I can't test it. No MicroSofty here.
Ian
thanz a lot guys for you all reply;
actually the error that came out after i compiled like "Del.java:120: eLogging(java.lang.String,java.
in Del cannot be applied to (java.lang.String,java.lang.String,java.io.FileNotFoundException)
eLogging("main", "adjab", e);"
this is the example that i want to write to a text file if there is any error when i compile.
pls help me to figure out this problem, and preferably provides me with an example codes..... really appreciate you all helps.....
If you want to write someting to a file including exception then following might help you.
import java.io.*;
public class WriteToFile{
FileOutputStream fos;
BufferedWriter wr;
public WriteToFile(){
try{
fos = new FileOutputStream("c:/MyError.txt");
wr=new BufferedWriter(new OutputStreamWriter(fos));
wr.write("My File");
wr.flush();
fos.close();
wr.close();
}
catch(Exception e){System.out.println(e);}
}
public static void main(String[] args){
new WriteToFile();
System.out.println("Check the file c:/MyError.txt");
}
}
Manu
thanz manu !!!
i think you get me wrong. my problem is during the runtime when i compiling the java file, i want to write all those error messages into a file. especially those "exception" that came out.... so it's during the runtime.....
i mean when compiling, those messages like :-
<className>.java:230: cannot resolve symbol
symbol : variable abc
location: class <className>
so this is the message that i want to write into a file. is there any possibility?
your helps truly appreciated
i think you have your jargon a little messed up ;-)
what you mean is compile time error messages. not 'runtime'. runtime means while you program is executing, get it?
anyway, you don't seem to have looked at the replies to this query of yours carefully. the reply that i gave (the 2nd one, in this thread) works on windoz
This works fine on Windows NT, but it does not work on Windows 98 for JDK 1.3 (Yes, I know I shouldn't use W98 for dev, but...).
Is it possible to write a class that writes output on stderr to a file (or a socket or whatever) and then execute javac using that? Any thoughts?