I am currently working on sending a file that contains one or more sentences through a parser, using command prompt.

C:\ exe argument1 file
is the format it must be sent it in command prompt

The parser works and will return the parsed sentences in the command prompt ranging from 1 to probably at most 20 lines. I want to know if there is a way to send in the text and read out the parsed lines from the prompt to a file and/or maybe a few pointers on getting there.

Many Thanks

8 Years
Discussion Span
Last Post by pkollmyr

Well, you could pipe the command line output directly to a file with just the OS syntax, but if you want your program to do the file writing just add use a second arg as the the output file path and use a BufferedWriter to write the output similar to this

if (args.length<2){
    System.out.println("Usage: <YourParserClass> inputFile outputFile");
File inFile = new File(args[0]);
File outFile = new File(args[1]);

// ... your operations here (including args validation)
// then write it out with BufferedWriter
try {
    BufferedWriter out = new BufferedWriter(new FileWriter(outFile));
    while ( stuffToWrite ){
        out.write( stuff );
        out.newLine(); // If you need to...
} catch (IOException e) {

what is the OS syntax to send it to a file from the command prompt?

I would change the source code of the parser but I did not program it. I was only given it with little known about it besides sending in text files.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.