Discussions

Web tier: servlets, JSP, Web frameworks: Writing to a text file

  1. Writing to a text file (1 messages)

    I need to write a string of information to a text file from my Java program. This text file will be read by an external VB program that I will have to kick off from the same program. I have a link on my page that has a javascript function that kicks off the external program using var wsh = new ActiveXObject('WScript.Shell'); I was successfully passing the string into the program but when I had to add additional information it took me over my 255 limitation of the WScript can process, the VB program also cannot process more than the 255 in it's debugger. The info up to 255 does displays but then everything there after is truncated. So my only option now is to rewrite the external program in Java, which I don't have time for. Or find a way to write to a text file that the VB program can read.

    Threaded Messages (1)

  2. try this[ Go to top ]

    To write to a file...

    <code>
    // open a file handle...
    PrintWriter out = new PrintWriter(new FileOutputStream(new File(filename)));
    // write to it...
    out.print("text");
    // close when you're done...
    out.close();
    </code>

    You'll need to wrap this in a try/catch block.
    To execute the vb program from within Java...

    <code>
    // execute process in a thread...
    Process proc = Runtime.getRuntime().exec("command to execute");
    // wait for it to finish before continuing...
    int exitStatus = proc.waitFor();
    </code>

    -Miik