|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
|||
|
|||
|
I am running JServ on linux and having trouble reading and writing files. My code works fine from a regular java application. Is there some trick to doing this from a servlet?
|
|
#2
|
|||
|
|||
|
Okay, so I'm that lame. hehe...
My bad code was my problem. To anyone with this same question, here is some code that actually works: ////////////////////////// //READING: try{ fis = new FileInputStream(getFullPath()); dis = new DataInputStream(fis); while( dis.available() != 0) { System.out.println(dis.readLine());} // I know, I know... // readline() is deprecated... : ( dis.close(); }catch(IOException e) { System.out.println(e.toString());} ///////////////////////////////////////// // Write something FileOutputStream fos = null; PrintStream p = null; try{ // Create a new file output stream fos = new FileOutputStream(getFullPath()); // Create a print stream using your new output stream p = new PrintStream( fos ); //Write something in the file p.println ("You are a freak!"); // free up the stream. p.close(); }catch(IOException e) {System.out.println("write file error" + e.toString());} |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Servlet File I/O |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|