Results 1 to 4 of 4
  1. #1
    Cylab is offline Member
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default 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???????????

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,311
    Blog Entries
    7
    Rep Power
    20

    Default

    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

  3. #3
    Cylab is offline Member
    Join Date
    Jun 2010
    Posts
    29
    Rep Power
    0

    Default

    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!

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,311
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Cylab View Post
    will be appreacited, if there is any further hint
    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:

    Java Code:
    private void setIn(String name) { ... }
    private void setOut(String name) { ...
     }
    ... 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:
    setOut("myOutFile.txt");
    setIn("myInFile1.txt"); method();
    setIn("myInFile2.txt"); method();
    setIn("myInFile3.txt"); method();
    System.out.close();
    kind regards,

    Jos

Similar Threads

  1. Logging Standard output to a file
    By jhyuk in forum Advanced Java
    Replies: 2
    Last Post: 11-09-2009, 11:31 PM
  2. Java, output string, getting correct output? HELP!
    By computerboyo in forum New To Java
    Replies: 2
    Last Post: 02-25-2009, 11:44 PM
  3. How to redirect the output
    By Java Tip in forum java.io
    Replies: 0
    Last Post: 04-04-2008, 02:36 PM
  4. Replies: 0
    Last Post: 03-11-2008, 12:25 PM
  5. How to redirect the output
    By JavaBean in forum Java Tip
    Replies: 0
    Last Post: 10-04-2007, 09:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •