Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Very frustrating problem with writing to a file, cannot find file when overwriting.

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    18
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Very frustrating problem with writing to a file, cannot find file when overwriting.

    Hi, I wrote a database program that works perfectly fine on my home computer with Java 1.7. However, when I run the same exact code on my school computer there is a problem with overwriting a text file. It says java.io.FileNotFoundException even though it works when I append the file by typing "true" after the file name. So basically it can't find the file when I want it to overwrite, but it can when I tell it to append. And I've made sure to close all previous input/output streams.

    I am using this line of code for the file writer:
    PrintWriter output = new PrintWriter(new FileWriter("textfile.txt"))

    Could different Java versions be a problem or the fact that my school computers are on windows XP? Is there any other way to write to the file instead of the above code? I never had this problem before, thanks.


  2. #2
    Junior Member
    Join Date
    Jun 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Very frustrating problem with writing to a file, cannot find file when overwriting.

    Try by giving the exact path
    PrintWriter output = new PrintWriter(new FileWriter("C:\\textfile.txt"))

Similar Threads

  1. Problem With File Writing
    By Madyastha in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: December 14th, 2012, 04:31 PM
  2. Frustrating File>save as search function in google script
    By segreto in forum Other Programming Languages
    Replies: 2
    Last Post: August 16th, 2012, 12:40 PM
  3. counting the values in input file and and writing the output to a file
    By srujirao in forum What's Wrong With My Code?
    Replies: 3
    Last Post: July 8th, 2012, 02:48 PM
  4. Overwriting txt file
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 29th, 2010, 08:21 AM
  5. Problem with overwriting a file using IO package
    By marksquall in forum File I/O & Other I/O Streams
    Replies: 6
    Last Post: March 28th, 2009, 06:37 AM