Results 1 to 4 of 4
Thread: Redirect standard output
- 08-07-2010, 03:27 PM #1
Member
- Join Date
- Jun 2010
- Posts
- 29
- Rep Power
- 0
Redirect standard output
Assumming that program name is "XML.java",
perform the followings for each input file:
java Xml < input1.txt
java Xml < input2.txt
:
Code:
class XML{
................main(String[] args){
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
String fileName = bf.readLine();
File file = new File(fileName);
FileReader fr = new FileReader(file);
StreamTokenizer st = new StreamTokenizer(fr);
:
processing
:
}
}
Question: but I can not redirect to file by >. How can I do?
Mind adding a few lines please???????????
- 08-07-2010, 03:41 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,411
- Blog Entries
- 7
- Rep Power
- 17
I'm sorry for sounding silly but I don't see any IO redirection in your code; note that there are the methods System.setOut( ... ) and System.setIn( ... )
kind regards,
Jos
- 08-07-2010, 04:21 PM #3
Member
- Join Date
- Jun 2010
- Posts
- 29
- Rep Power
- 0
Thanks Jos!!!!!
you are always prompt and helpful.
From your hint I am still searching.............
will be appreacited, if there is any further hint
Thanks again!
- 08-07-2010, 04:35 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,411
- Blog Entries
- 7
- Rep Power
- 17
No more hints from me (because I don't know of any) but if I had to do it I would create two simple methods:
... that redirect the input resp. the output stream to a FileStream given the name of the file. Then, given a method that reads from System.in and writes to System.out, I'd be able to do:Java Code:private void setIn(String name) { ... } private void setOut(String name) { ... }
kind regards,Java Code:setOut("myOutFile.txt"); setIn("myInFile1.txt"); method(); setIn("myInFile2.txt"); method(); setIn("myInFile3.txt"); method(); System.out.close();
Jos
Similar Threads
-
Logging Standard output to a file
By jhyuk in forum Advanced JavaReplies: 2Last Post: 11-09-2009, 11:31 PM -
Java, output string, getting correct output? HELP!
By computerboyo in forum New To JavaReplies: 2Last Post: 02-25-2009, 11:44 PM -
How to redirect the output
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:36 PM -
how to redirect the output buffer of pl/sql onto a jsp
By sriavr in forum JDBCReplies: 0Last Post: 03-11-2008, 12:25 PM -
How to redirect the output
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:30 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks