p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

java_howto thread: HOW DO YOU WRITE TO A NETWORK DEVICE FROM JSP?


Message #1 by "jsp_user" <LOBNA.MAKTARI@D...> on Wed, 21 Mar 2001 14:12:25
The following code works fine from within an applet.  The code has been 
extracted into a JSP page (shown below) and also works fine.
From within the applet, I can also successfully substitute the local 
filenames with network filenames eg. new FileReader("\\\\Server1\\Laser1") 
and write to a network drive and network printer.  However, using the 
above from JSP doesn't work. 

Does anybody know why or how to overcome this infuriating problem?  


//1.  read from local drive, char by char 
    FileReader infile = new FileReader("c:\\intermeclm.prn");
    StringBuffer contents = new StringBuffer();
    int charBytes;
    charBytes = infile.read();
    while (charBytes!=-1)
    {
      contents.append( (char) charBytes);
      charBytes = infile.read();
    }
    infile.close();

  //2.  And write back to local drive
  FileWriter outfile = new FileWriter("c:\\intermeclm2.prn");
    for (int i=0;i<contents.length(); i++)
      outfile.write((int) contents.charAt(i));
    outfile.flush();
    outfile.close();

  Return to Index