PrintWrite keeps throwing a file not found exception even though the file referenced is in the project root directory
up vote
0
down vote
favorite
The file data.txt is in the root directory of my project and it keeps throwing exceptions. What might be the problem?
public static void Records(String record)
File file = new File("data.txt");
PrintWriter pw = new PrintWriter(file);
pw.println(record + "n");
pw.close();
java
add a comment |
up vote
0
down vote
favorite
The file data.txt is in the root directory of my project and it keeps throwing exceptions. What might be the problem?
public static void Records(String record)
File file = new File("data.txt");
PrintWriter pw = new PrintWriter(file);
pw.println(record + "n");
pw.close();
java
There should not be any problem with this, can you take a look at your code once again, because this seems like a code that should work.
– PradyumanDixit
Nov 10 at 6:10
Seems to work, forgot to put a throw clause in the main method. Now it only writes the last record though. How could I get it to simply just add lines and not rewrite the whole file?
– Jake The Steak
Nov 10 at 6:32
useFileWriter
@JakeTheSteak
– Deadpool
Nov 10 at 6:38
Please post the exception stacktrace.
– Mark Rotteveel
Nov 11 at 11:28
Try using append: pw.append(record + "n");
– Perdi Estaquel
Nov 27 at 5:44
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
The file data.txt is in the root directory of my project and it keeps throwing exceptions. What might be the problem?
public static void Records(String record)
File file = new File("data.txt");
PrintWriter pw = new PrintWriter(file);
pw.println(record + "n");
pw.close();
java
The file data.txt is in the root directory of my project and it keeps throwing exceptions. What might be the problem?
public static void Records(String record)
File file = new File("data.txt");
PrintWriter pw = new PrintWriter(file);
pw.println(record + "n");
pw.close();
java
java
asked Nov 10 at 6:05
Jake The Steak
61
61
There should not be any problem with this, can you take a look at your code once again, because this seems like a code that should work.
– PradyumanDixit
Nov 10 at 6:10
Seems to work, forgot to put a throw clause in the main method. Now it only writes the last record though. How could I get it to simply just add lines and not rewrite the whole file?
– Jake The Steak
Nov 10 at 6:32
useFileWriter
@JakeTheSteak
– Deadpool
Nov 10 at 6:38
Please post the exception stacktrace.
– Mark Rotteveel
Nov 11 at 11:28
Try using append: pw.append(record + "n");
– Perdi Estaquel
Nov 27 at 5:44
add a comment |
There should not be any problem with this, can you take a look at your code once again, because this seems like a code that should work.
– PradyumanDixit
Nov 10 at 6:10
Seems to work, forgot to put a throw clause in the main method. Now it only writes the last record though. How could I get it to simply just add lines and not rewrite the whole file?
– Jake The Steak
Nov 10 at 6:32
useFileWriter
@JakeTheSteak
– Deadpool
Nov 10 at 6:38
Please post the exception stacktrace.
– Mark Rotteveel
Nov 11 at 11:28
Try using append: pw.append(record + "n");
– Perdi Estaquel
Nov 27 at 5:44
There should not be any problem with this, can you take a look at your code once again, because this seems like a code that should work.
– PradyumanDixit
Nov 10 at 6:10
There should not be any problem with this, can you take a look at your code once again, because this seems like a code that should work.
– PradyumanDixit
Nov 10 at 6:10
Seems to work, forgot to put a throw clause in the main method. Now it only writes the last record though. How could I get it to simply just add lines and not rewrite the whole file?
– Jake The Steak
Nov 10 at 6:32
Seems to work, forgot to put a throw clause in the main method. Now it only writes the last record though. How could I get it to simply just add lines and not rewrite the whole file?
– Jake The Steak
Nov 10 at 6:32
use
FileWriter
@JakeTheSteak– Deadpool
Nov 10 at 6:38
use
FileWriter
@JakeTheSteak– Deadpool
Nov 10 at 6:38
Please post the exception stacktrace.
– Mark Rotteveel
Nov 11 at 11:28
Please post the exception stacktrace.
– Mark Rotteveel
Nov 11 at 11:28
Try using append: pw.append(record + "n");
– Perdi Estaquel
Nov 27 at 5:44
Try using append: pw.append(record + "n");
– Perdi Estaquel
Nov 27 at 5:44
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53236432%2fprintwrite-keeps-throwing-a-file-not-found-exception-even-though-the-file-refere%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
There should not be any problem with this, can you take a look at your code once again, because this seems like a code that should work.
– PradyumanDixit
Nov 10 at 6:10
Seems to work, forgot to put a throw clause in the main method. Now it only writes the last record though. How could I get it to simply just add lines and not rewrite the whole file?
– Jake The Steak
Nov 10 at 6:32
use
FileWriter
@JakeTheSteak– Deadpool
Nov 10 at 6:38
Please post the exception stacktrace.
– Mark Rotteveel
Nov 11 at 11:28
Try using append: pw.append(record + "n");
– Perdi Estaquel
Nov 27 at 5:44