how to write file from dos command window to a file

is there anybody that can help me here? currently i compile my java file from dos command window. is there anyway that i can write it to a file whatever wording came out from the dos command window? i mean what command i should write it... please help me as i am new using java !!!
[295 byte] By [eastkid] at [2007-9-26 2:05:13]
# 1

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");

}

}

98028140 at 2007-6-29 8:49:59 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 2
do you mean redirecting the output from the compiler? i guess you are getting plenty of compilation error messages, and they are scrolling off the top of the dos box.try thisjavac YourClass.java 2> error.log
parthasarkar at 2007-6-29 8:49:59 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 3

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.

unknow at 2007-6-29 8:49:59 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 4

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

IanMechura at 2007-6-29 8:49:59 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 5

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.....

eastkid at 2007-6-29 8:49:59 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 6

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

manu176 at 2007-6-29 8:49:59 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 7

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

eastkid at 2007-6-29 8:49:59 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 8

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

parthasarkar at 2007-6-29 8:49:59 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 9
It might be that the compile errors gets written on stderr, not stdout. I don't recall exactly how you redirect stderr in DOS, but I think it was quite similar to the unix way. Something like: javac foo.java @2> error.txt
LiljedahlPA at 2007-6-29 8:49:59 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 10
Ok, now got you.Try this.javac javafile.java 2>MyError.txtIt will redirect the output to the file "MyError.txt" and in there you can easly view the errors.Manu
manu176 at 2007-6-29 8:49:59 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 11

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?

argherna at 2007-6-29 8:49:59 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 12
Try this (I am using Win98):oldjavac -Xstdout aFileName.java > out1.txt
oldguy1 at 2007-6-29 8:49:59 > top of Java-index,Archived Forums,New To Java Technology Archive...