fubarable

PrintWriter fun

Sep 24th, 2016
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. try{
  2.     //Create a file writer that will write the file
  3.     FileWriter fw = new FileWriter("c://Users/Mike/workspace/"+filename);
  4.     //Create print writer
  5.     PrintWriter fp = new PrintWriter(fw);
  6.     //Print to the file each line coming in from the client
  7.     String fileLine;
  8.     while((fileLine = bf.readLine()) != null) {
  9.         fp.println(fileLine);
  10.         System.out.println("added line "+fileLine);//test by printing to console
  11.     }
  12.     // if (fp == null) { // !!! NO !!!
  13.     if (fp != null) {  // !! YES !!!
  14.         //close the file printer, inform the client the upload is complete
  15.         fp.close();
  16.         out.println("Upload Complete!");  // ?? should this be System.out.println(...)??
  17.     } else {
  18.         System.out.println("fp already null -- upload complete");
  19.     }
  20. } catch(IOException e) {
  21.     e.printStacktrace();
  22. }
Add Comment
Please, Sign In to add comment