how to write to txt file

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Feb 2009
Posts: 12
Reputation: thijo is an unknown quantity at this point 
Solved Threads: 0
thijo thijo is offline Offline
Newbie Poster

Re: how to write to txt file

 
0
  #11
Mar 11th, 2009
hi,
I think the problem could not be solved since we cannot implement user interaction using java runtime(). so i just used buffered file writer if you have any suggestion plz inform me.
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 823
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

Re: how to write to txt file

 
0
  #12
Mar 11th, 2009
See the example that I mentioned in post # 2
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 759
Reputation: Killer_Typo will become famous soon enough Killer_Typo will become famous soon enough 
Solved Threads: 35
Killer_Typo's Avatar
Killer_Typo Killer_Typo is offline Offline
Master Poster

Re: how to write to txt file

 
0
  #13
Mar 12th, 2009
you need to preappend

cmd /c

my example I tested:

  1. package redirectconsoleoutput;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6.  
  7. /**
  8.  *
  9.  * @author Michael
  10.  */
  11. public class Main {
  12.  
  13. /**
  14.   * @param args the command line arguments
  15.   */
  16. public static void main( String[] args ) {
  17. // TODO code application logic here
  18. System.out.println("Attempting to redirect the output of one java app to another");
  19. String s = null;
  20.  
  21. try {
  22. Process p = Runtime.getRuntime().exec("cmd /c java -jar \"D:\\Users\\Michael\\Documents\\NetBeansProjects\\SortedSetReWrite\\dist\\SortedSetReWrite.jar\" > \"D:\\SortedSetReWrite.txt\"");
  23.  
  24. BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
  25.  
  26. BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
  27.  
  28. // read the output from the command
  29.  
  30. System.out.println("Here is the standard output of the command:\n");
  31. while ( (s = stdInput.readLine()) != null ) {
  32. System.out.println(s);
  33. }
  34.  
  35. // read any errors from the attempted command
  36.  
  37. System.out.println("Here is the standard error of the command (if any):\n");
  38. while ( (s = stdError.readLine()) != null ) {
  39. System.out.println(s);
  40. }
  41.  
  42. System.exit(0);
  43.  
  44. } catch ( IOException e ) {
  45. System.out.println(e.getMessage());
  46. System.exit(-1);
  47. }
  48.  
  49. }
  50. }
Last edited by Killer_Typo; Mar 12th, 2009 at 4:46 am.
Dont forget to spread the reputation to those that deserve!
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 1
Reputation: lelakijadian is an unknown quantity at this point 
Solved Threads: 0
lelakijadian lelakijadian is offline Offline
Newbie Poster

Re: how to write to txt file

 
0
  #14
Mar 12th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,711
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 229
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: how to write to txt file

 
0
  #15
Mar 12th, 2009
Originally Posted by lelakijadian View Post
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.
Start a new thread.

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
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 2
Reputation: Lisa1110 is an unknown quantity at this point 
Solved Threads: 0
Lisa1110 Lisa1110 is offline Offline
Newbie Poster

Re: how to write to txt file

 
0
  #16
Mar 12th, 2009
You can use a PrintWriter over an OutputStream like the FileOutputStream. The FileOutputStream can be opened on a File object, or a string that specifies the filepath.

Lisa11

<snip fake signature>
Last edited by Ancient Dragon; Mar 12th, 2009 at 8:06 am. Reason: snip fake signature
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC