| | |
how to write to txt file
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
you need to preappend
cmd /c
my example I tested:
cmd /c
my example I tested:
java Syntax (Toggle Plain Text)
package redirectconsoleoutput; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * * @author Michael */ public class Main { /** * @param args the command line arguments */ public static void main( String[] args ) { // TODO code application logic here System.out.println("Attempting to redirect the output of one java app to another"); String s = null; try { Process p = Runtime.getRuntime().exec("cmd /c java -jar \"D:\\Users\\Michael\\Documents\\NetBeansProjects\\SortedSetReWrite\\dist\\SortedSetReWrite.jar\" > \"D:\\SortedSetReWrite.txt\""); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream())); // read the output from the command System.out.println("Here is the standard output of the command:\n"); while ( (s = stdInput.readLine()) != null ) { System.out.println(s); } // read any errors from the attempted command System.out.println("Here is the standard error of the command (if any):\n"); while ( (s = stdError.readLine()) != null ) { System.out.println(s); } System.exit(0); } catch ( IOException e ) { System.out.println(e.getMessage()); System.exit(-1); } } }
Last edited by Killer_Typo; Mar 12th, 2009 at 4:46 am.
Dont forget to spread the reputation to those that deserve!
•
•
•
•
hey guys...i have one question.i have file Sample.data, in that file i write "Hello world". how to write code to separate word between "Hello" and "world" and print out it as output seperately.
Or better search this forum. Your question has been answered a million times
Check out my New Bike at my Public Profile at the "About Me" tab
![]() |
Similar Threads
- Why my executable jar file cant write a text file (Java)
- Need to write postfix to a file (Java)
- The Fastest way to read a .txt File (C++)
- how to write a .txt file (C++)
- Write determinate controls to txt file (C#)
- getting words from .txt file (C++)
- .txt file formatting assignment due TODAY help!! (C)
Other Threads in the Java Forum
- Previous Thread: Compiling error
- Next Thread: Terminal Window in a GUI
| Thread Tools | Search this Thread |
Tag cloud for Java
affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth businessintelligence chat class classes client code component database desktop draw ebook eclipse encode equation error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer intersect j2me java javaexcel javaprojects jmf jni jpanel julia linked linux list loop mac main map method methods mobile netbeans newbie number online open-source oracle parameter print problem program programming project properties recursion reference replaysolutions rotatetext scanner score screen scrollbar server set size sms socket sort sql string superclass swing template test threads time tree windows working xstream






