Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By gimbal2

Thread: Can using the same files in different methods cause problems?

  1. #1
    Fluffy93 is offline Member
    Join Date
    Aug 2014
    Posts
    32
    Rep Power
    0

    Default Can using the same files in different methods cause problems?

    I started a topic off on Code Ranch. I am posting here also in an attempt to broaden my scope in the hope of finding my answer. I know my code sample file of renaming a file and deleting an original file will work fine but when I use the code within my main java file - it appears to populate the file that I want populating fine but wont delete the origional. I have everything on my c drive so I can very easily keep track of what files I do and don't have.



    Can using the same files in different methods cause problems? (Beginning Java forum at JavaRanch)


    Thanks in advance to anyone who can get a better understanding than myself as to why this does not work and could perhaps be kind enough to point it out.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Can using the same files in different methods cause problems?

    Just a tip: you removed too much of the code, add back the code where you actually create the readers and writers.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    Fluffy93 is offline Member
    Join Date
    Aug 2014
    Posts
    32
    Rep Power
    0

    Default Re: Can using the same files in different methods cause problems?

    I added more code :) after I stopped running it I couldn't edit the file it was telling me it was still in use I know its why I can't delete it but I thought closing the readers/writer would of worked!

  4. #4
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: Can using the same files in different methods cause problems?

    It -should- work, unless some other piece of code still has a file handle open to the file. And you only need to close the BuffedReader, that will implicitly also close the reader it is wrapped around (so remove that fr.close()). That is a very important system that prevents you from closing stuff in the wrong order, like you were doing in the original code you posted.

    I'm sorry but I find it very chaotic to discuss something which is posted somewhere else. I'm going to leave it at this. Hopefully someone on the ranch will wake up.
    Fluffy93 likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    Fluffy93 is offline Member
    Join Date
    Aug 2014
    Posts
    32
    Rep Power
    0

    Default Re: Can using the same files in different methods cause problems?

    Thats just made me think - I have other readers open in another method I wonder if I have closed them or not correctly - thank you for pointing that out!

Similar Threads

  1. Problems with using other classes methods/instances
    By laMonaca in forum New To Java
    Replies: 4
    Last Post: 01-19-2013, 01:57 PM
  2. Problems with morphing Methods
    By wallyll in forum New To Java
    Replies: 1
    Last Post: 11-13-2012, 04:34 PM
  3. problems with multiple methods and paramaters...
    By silafirion in forum New To Java
    Replies: 13
    Last Post: 12-07-2010, 01:10 AM
  4. Having problems with methods
    By JavatastesGood in forum New To Java
    Replies: 2
    Last Post: 10-02-2010, 10:57 PM
  5. Problems With Array/Methods
    By blueduiker in forum New To Java
    Replies: 4
    Last Post: 01-19-2010, 01:49 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •