On Mon, 24 May 1999 09:24:15 +0100
Gustavo Medina del Rosario <[EMAIL PROTECTED]> wrote

>     I am trying to write e file in a server from an applet. My applet
> ask some questions to the user (name, address, etc.) and proccess the
> information and I want it to write in the server (where the applet is
> stored) in a text file.
> 
>     Some people in spain emailed me that it can be made with the URL
> class but I can't.

I am certain you can write to a file on the server from which the 
applet started. I have not written to a file, but I have read from a 
file on the same server. Here is the code for reading from a file. I 
am sure it can be easily modified to write to file on the server. I 
the example below, CarDriver is simply a class to hold data from the 
file. I did not include it, because the file access code is what is 
of interest here.

  /**
   * get data from the server on which the applet started
   * for ParkingLot database and put into a Vector
   * and Hash Table of car drivers
   * @exception MalformedURLException
   * @exception IOException
   */
  public void readParkingLotData() {

     try {
       // Connect to the file at the url of this applet
       URL dataFile = new URL(getDocumentBase(), FILE_NAME);

       // Open an input stream to the datafile at the url
       InputStreamReader inputStream = new 
InputStreamReader(dataFile.openStream());

       // Assign a buffered reader to the input stream
       BufferedReader bufReader = new BufferedReader(inputStream);

       while ( true ) {
         String line = bufReader.readLine();
         if ( line == null ) {
           break;
         } else {
           CarDriver carDriver = getDriverAndCar(line);

           // put into vector and hashtable
           if ( carDriver != null ) {
             carDriversVector.addElement(carDriver);
             carDriversHash.put(carDriver.getCar().getLicensePlate(), 
carDriver);
           }
         }
       }
     }
     catch (MalformedURLException e) {
       licensePlateField.setText("Error: Could not open the data file 
'" +
                            FILE_NAME +
                            "' on the server.");
     }
     catch (IOException e) {
       licensePlateField.setText("Error: Could not open the data file 
'" +
                            FILE_NAME +
                            "' on the server.");
     }
  }

... larry

--------------------------------------------------
Larry Arnoldy
E-mail: [EMAIL PROTECTED]
www: http://faculty.ed.umuc.edu/~larnoldy
www: http://www.geocities.com/SiliconValley/Port/6488/
ICQ: 18758505; Instant Msg: larnoldy

Work phone: (Germany) +49 6221 378325
Work fax:   (Germany) +49 6221 378305
Work inhouse phone: 245
--------------------------------------------------


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to