[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

prtintWriter not working

hi i have this piece of code which i intend to run in thru rmiregistry      
there is no error in the compilation however no file is being created here..I wonder why???

--------------------------


public void saveUser(UserProfile currProfile) throws FileNotFoundException,IOException,RemoteException
      {
              
              PrintWriter outs = new PrintWriter( new FileWriter( "z:\\cs310\\assn5\\userprofiles.txt" ) );
                  
                  
              save2DB(currProfile,outs);

      }
      
      private void save2DB(UserProfile currProfile, PrintWriter pp) //local helper function
      {
      
                  System.out.println(" WRITING ");
                  pp.println("bah")
                  pp.println(currProfile.getName()+ "," + currProfile.getLoginID()+ "," + currProfile.getPassword()+ "," + currProfile.getEmailAddress()+ "," + currProfile.getPhoneNumber()+ "," + currProfile.getUserType());
                  
                  pp.close();
                  System.out.println(" FIN WRITING ");
                  
            
            
      }

0
tom_mk
Asked:
tom_mk
  • 3
  • 2
  • 2
2 Solutions
 
objectsCommented:
PrintWriter fails silently, call pp.checkError() to see if there was a problem.
0
 
petmagdyCommented:
make sure that the directory is created and have write access try this:

        File file = new File("c:\\tempo\\userprofiles.txt") ;  
        PrintWriter outs = new PrintWriter( new FileWriter( file ) );
0
 
tom_mkAuthor Commented:
but, even though the file does not exist, the printWriter just going to create it for me..right?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
objectsCommented:
yes if it has permission to.
0
 
petmagdyCommented:
yes but the directory must be created and have write access and use my way which is:
    File file = new File("z:\\...\\userprofiles.txt") ;
        PrintWriter outs = new PrintWriter( new FileWriter( file ) );
0
 
tom_mkAuthor Commented:
how can i have the write access?
0
 
petmagdyCommented:
please try ur code on local Harddisk first if works contact the share owner asking for write access
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now