I can't get netbeans to find a txt file I have in the same directory… java.io.FileNotFoundException
I can't make it path specific because once I get this program to work (this is the last thing I have to do) I'm uploading to my university's ilearn website and it has to run on my professors computer with no modifications. I've tried a few different amalgamations of code similar to the following...
File file = new File("DataFile.txt");
Scanner document = new Scanner(new File("DataFile.txt"));
Or...
java.io.File file = new java.io.File("DataFile.txt");
Scanner document = new Scanner(file);
But nothing seems to work. I've got the necessary stuff imported. I've tried moving DataFile
around in a few different folders (the src
folder, and other random folders in the project's NetBeansProjects
folder) I tried creating a folder in the project and putting the file in that folder and trying to use some kind of
documents/DataFile.txt
bit I found online (I named the folder documents).
I've tried renaming the file, saving it in different ways. I'm all out of ideas.
The file is just a list of numbers that are used in generating random data for this program we got assigned for building a gas station simulator. The program runs great when I just use user input from the console. But I can not get netbeans to find that file for the life of me! Help!?!?!?
file-io filenotfoundexception
add a comment |
I can't make it path specific because once I get this program to work (this is the last thing I have to do) I'm uploading to my university's ilearn website and it has to run on my professors computer with no modifications. I've tried a few different amalgamations of code similar to the following...
File file = new File("DataFile.txt");
Scanner document = new Scanner(new File("DataFile.txt"));
Or...
java.io.File file = new java.io.File("DataFile.txt");
Scanner document = new Scanner(file);
But nothing seems to work. I've got the necessary stuff imported. I've tried moving DataFile
around in a few different folders (the src
folder, and other random folders in the project's NetBeansProjects
folder) I tried creating a folder in the project and putting the file in that folder and trying to use some kind of
documents/DataFile.txt
bit I found online (I named the folder documents).
I've tried renaming the file, saving it in different ways. I'm all out of ideas.
The file is just a list of numbers that are used in generating random data for this program we got assigned for building a gas station simulator. The program runs great when I just use user input from the console. But I can not get netbeans to find that file for the life of me! Help!?!?!?
file-io filenotfoundexception
Welcome to StackOverflow. Please notice that when you're asking a question, there's a preview displayed directly below that you can use to check things like code and text formatting. Also, when adding any source code, you can format it properly by pasting it and then indenting it by four or more spaces, or by selecting it all and then either 1) Clicking the button that looks like{}
on the toolbar, or 2) usingCtrl+K
. Inline text can be formatted by surrounding it in backticks (the character to the left of the1
on most US keyboards), or `. Thanks. :)
– Ken White
Nov 24 '11 at 5:27
add a comment |
I can't make it path specific because once I get this program to work (this is the last thing I have to do) I'm uploading to my university's ilearn website and it has to run on my professors computer with no modifications. I've tried a few different amalgamations of code similar to the following...
File file = new File("DataFile.txt");
Scanner document = new Scanner(new File("DataFile.txt"));
Or...
java.io.File file = new java.io.File("DataFile.txt");
Scanner document = new Scanner(file);
But nothing seems to work. I've got the necessary stuff imported. I've tried moving DataFile
around in a few different folders (the src
folder, and other random folders in the project's NetBeansProjects
folder) I tried creating a folder in the project and putting the file in that folder and trying to use some kind of
documents/DataFile.txt
bit I found online (I named the folder documents).
I've tried renaming the file, saving it in different ways. I'm all out of ideas.
The file is just a list of numbers that are used in generating random data for this program we got assigned for building a gas station simulator. The program runs great when I just use user input from the console. But I can not get netbeans to find that file for the life of me! Help!?!?!?
file-io filenotfoundexception
I can't make it path specific because once I get this program to work (this is the last thing I have to do) I'm uploading to my university's ilearn website and it has to run on my professors computer with no modifications. I've tried a few different amalgamations of code similar to the following...
File file = new File("DataFile.txt");
Scanner document = new Scanner(new File("DataFile.txt"));
Or...
java.io.File file = new java.io.File("DataFile.txt");
Scanner document = new Scanner(file);
But nothing seems to work. I've got the necessary stuff imported. I've tried moving DataFile
around in a few different folders (the src
folder, and other random folders in the project's NetBeansProjects
folder) I tried creating a folder in the project and putting the file in that folder and trying to use some kind of
documents/DataFile.txt
bit I found online (I named the folder documents).
I've tried renaming the file, saving it in different ways. I'm all out of ideas.
The file is just a list of numbers that are used in generating random data for this program we got assigned for building a gas station simulator. The program runs great when I just use user input from the console. But I can not get netbeans to find that file for the life of me! Help!?!?!?
file-io filenotfoundexception
file-io filenotfoundexception
edited Nov 24 '11 at 5:28
Ken White
107k11155317
107k11155317
asked Nov 24 '11 at 4:50
Tim BauerTim Bauer
11112
11112
Welcome to StackOverflow. Please notice that when you're asking a question, there's a preview displayed directly below that you can use to check things like code and text formatting. Also, when adding any source code, you can format it properly by pasting it and then indenting it by four or more spaces, or by selecting it all and then either 1) Clicking the button that looks like{}
on the toolbar, or 2) usingCtrl+K
. Inline text can be formatted by surrounding it in backticks (the character to the left of the1
on most US keyboards), or `. Thanks. :)
– Ken White
Nov 24 '11 at 5:27
add a comment |
Welcome to StackOverflow. Please notice that when you're asking a question, there's a preview displayed directly below that you can use to check things like code and text formatting. Also, when adding any source code, you can format it properly by pasting it and then indenting it by four or more spaces, or by selecting it all and then either 1) Clicking the button that looks like{}
on the toolbar, or 2) usingCtrl+K
. Inline text can be formatted by surrounding it in backticks (the character to the left of the1
on most US keyboards), or `. Thanks. :)
– Ken White
Nov 24 '11 at 5:27
Welcome to StackOverflow. Please notice that when you're asking a question, there's a preview displayed directly below that you can use to check things like code and text formatting. Also, when adding any source code, you can format it properly by pasting it and then indenting it by four or more spaces, or by selecting it all and then either 1) Clicking the button that looks like
{}
on the toolbar, or 2) using Ctrl+K
. Inline text can be formatted by surrounding it in backticks (the character to the left of the 1
on most US keyboards), or `. Thanks. :)– Ken White
Nov 24 '11 at 5:27
Welcome to StackOverflow. Please notice that when you're asking a question, there's a preview displayed directly below that you can use to check things like code and text formatting. Also, when adding any source code, you can format it properly by pasting it and then indenting it by four or more spaces, or by selecting it all and then either 1) Clicking the button that looks like
{}
on the toolbar, or 2) using Ctrl+K
. Inline text can be formatted by surrounding it in backticks (the character to the left of the 1
on most US keyboards), or `. Thanks. :)– Ken White
Nov 24 '11 at 5:27
add a comment |
2 Answers
2
active
oldest
votes
Try adding the file to build path ..
Awesome! I'd love to. How do I do that?
– Tim Bauer
Nov 24 '11 at 4:55
stackoverflow.com/questions/5072127/…
– Akhil Thayyil
Nov 24 '11 at 4:58
I tried putting the file in the build folder and used the java.io.File file = new java.io.File("DataFile.txt"); Scanner document = new Scanner(file); but to no avail...
– Tim Bauer
Nov 24 '11 at 5:00
PLease read this java.net/node/674233
– Akhil Thayyil
Nov 24 '11 at 5:10
add a comment |
public void readTextFile (){
try{
Scanner scFile =new Scanner(new File("filename.txt");
while(scFile.hasNext()){
String line =scFile.nextLine();
Scanner details=new Scanner(line).useDelimiter("symbol");
than you can work from there to store integer values use e.g in an array
litterArr(size)=details.nextInt();
Note: size is a variable counting the size/number of info the array has.
}
scFile.close();
{
catch
(FILENOTFOUNDEXCEPION e){
..... *code*
}
Keep file in the same folder as the program,but if it is saved in another folder you need to supply the path indicating the location of the file as part of the file name e.g memAthletics.Lines.LoadFromFile('C:MyFilesAthletics.txt');
hope this helps clear the problem up :)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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%2f8252348%2fi-cant-get-netbeans-to-find-a-txt-file-i-have-in-the-same-directory-java-io%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Try adding the file to build path ..
Awesome! I'd love to. How do I do that?
– Tim Bauer
Nov 24 '11 at 4:55
stackoverflow.com/questions/5072127/…
– Akhil Thayyil
Nov 24 '11 at 4:58
I tried putting the file in the build folder and used the java.io.File file = new java.io.File("DataFile.txt"); Scanner document = new Scanner(file); but to no avail...
– Tim Bauer
Nov 24 '11 at 5:00
PLease read this java.net/node/674233
– Akhil Thayyil
Nov 24 '11 at 5:10
add a comment |
Try adding the file to build path ..
Awesome! I'd love to. How do I do that?
– Tim Bauer
Nov 24 '11 at 4:55
stackoverflow.com/questions/5072127/…
– Akhil Thayyil
Nov 24 '11 at 4:58
I tried putting the file in the build folder and used the java.io.File file = new java.io.File("DataFile.txt"); Scanner document = new Scanner(file); but to no avail...
– Tim Bauer
Nov 24 '11 at 5:00
PLease read this java.net/node/674233
– Akhil Thayyil
Nov 24 '11 at 5:10
add a comment |
Try adding the file to build path ..
Try adding the file to build path ..
answered Nov 24 '11 at 4:54
Akhil ThayyilAkhil Thayyil
7,67652440
7,67652440
Awesome! I'd love to. How do I do that?
– Tim Bauer
Nov 24 '11 at 4:55
stackoverflow.com/questions/5072127/…
– Akhil Thayyil
Nov 24 '11 at 4:58
I tried putting the file in the build folder and used the java.io.File file = new java.io.File("DataFile.txt"); Scanner document = new Scanner(file); but to no avail...
– Tim Bauer
Nov 24 '11 at 5:00
PLease read this java.net/node/674233
– Akhil Thayyil
Nov 24 '11 at 5:10
add a comment |
Awesome! I'd love to. How do I do that?
– Tim Bauer
Nov 24 '11 at 4:55
stackoverflow.com/questions/5072127/…
– Akhil Thayyil
Nov 24 '11 at 4:58
I tried putting the file in the build folder and used the java.io.File file = new java.io.File("DataFile.txt"); Scanner document = new Scanner(file); but to no avail...
– Tim Bauer
Nov 24 '11 at 5:00
PLease read this java.net/node/674233
– Akhil Thayyil
Nov 24 '11 at 5:10
Awesome! I'd love to. How do I do that?
– Tim Bauer
Nov 24 '11 at 4:55
Awesome! I'd love to. How do I do that?
– Tim Bauer
Nov 24 '11 at 4:55
stackoverflow.com/questions/5072127/…
– Akhil Thayyil
Nov 24 '11 at 4:58
stackoverflow.com/questions/5072127/…
– Akhil Thayyil
Nov 24 '11 at 4:58
I tried putting the file in the build folder and used the java.io.File file = new java.io.File("DataFile.txt"); Scanner document = new Scanner(file); but to no avail...
– Tim Bauer
Nov 24 '11 at 5:00
I tried putting the file in the build folder and used the java.io.File file = new java.io.File("DataFile.txt"); Scanner document = new Scanner(file); but to no avail...
– Tim Bauer
Nov 24 '11 at 5:00
PLease read this java.net/node/674233
– Akhil Thayyil
Nov 24 '11 at 5:10
PLease read this java.net/node/674233
– Akhil Thayyil
Nov 24 '11 at 5:10
add a comment |
public void readTextFile (){
try{
Scanner scFile =new Scanner(new File("filename.txt");
while(scFile.hasNext()){
String line =scFile.nextLine();
Scanner details=new Scanner(line).useDelimiter("symbol");
than you can work from there to store integer values use e.g in an array
litterArr(size)=details.nextInt();
Note: size is a variable counting the size/number of info the array has.
}
scFile.close();
{
catch
(FILENOTFOUNDEXCEPION e){
..... *code*
}
Keep file in the same folder as the program,but if it is saved in another folder you need to supply the path indicating the location of the file as part of the file name e.g memAthletics.Lines.LoadFromFile('C:MyFilesAthletics.txt');
hope this helps clear the problem up :)
add a comment |
public void readTextFile (){
try{
Scanner scFile =new Scanner(new File("filename.txt");
while(scFile.hasNext()){
String line =scFile.nextLine();
Scanner details=new Scanner(line).useDelimiter("symbol");
than you can work from there to store integer values use e.g in an array
litterArr(size)=details.nextInt();
Note: size is a variable counting the size/number of info the array has.
}
scFile.close();
{
catch
(FILENOTFOUNDEXCEPION e){
..... *code*
}
Keep file in the same folder as the program,but if it is saved in another folder you need to supply the path indicating the location of the file as part of the file name e.g memAthletics.Lines.LoadFromFile('C:MyFilesAthletics.txt');
hope this helps clear the problem up :)
add a comment |
public void readTextFile (){
try{
Scanner scFile =new Scanner(new File("filename.txt");
while(scFile.hasNext()){
String line =scFile.nextLine();
Scanner details=new Scanner(line).useDelimiter("symbol");
than you can work from there to store integer values use e.g in an array
litterArr(size)=details.nextInt();
Note: size is a variable counting the size/number of info the array has.
}
scFile.close();
{
catch
(FILENOTFOUNDEXCEPION e){
..... *code*
}
Keep file in the same folder as the program,but if it is saved in another folder you need to supply the path indicating the location of the file as part of the file name e.g memAthletics.Lines.LoadFromFile('C:MyFilesAthletics.txt');
hope this helps clear the problem up :)
public void readTextFile (){
try{
Scanner scFile =new Scanner(new File("filename.txt");
while(scFile.hasNext()){
String line =scFile.nextLine();
Scanner details=new Scanner(line).useDelimiter("symbol");
than you can work from there to store integer values use e.g in an array
litterArr(size)=details.nextInt();
Note: size is a variable counting the size/number of info the array has.
}
scFile.close();
{
catch
(FILENOTFOUNDEXCEPION e){
..... *code*
}
Keep file in the same folder as the program,but if it is saved in another folder you need to supply the path indicating the location of the file as part of the file name e.g memAthletics.Lines.LoadFromFile('C:MyFilesAthletics.txt');
hope this helps clear the problem up :)
edited Oct 26 '14 at 13:07
answered Oct 26 '14 at 12:52
TianaTiana
11
11
add a comment |
add a comment |
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.
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%2f8252348%2fi-cant-get-netbeans-to-find-a-txt-file-i-have-in-the-same-directory-java-io%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
Welcome to StackOverflow. Please notice that when you're asking a question, there's a preview displayed directly below that you can use to check things like code and text formatting. Also, when adding any source code, you can format it properly by pasting it and then indenting it by four or more spaces, or by selecting it all and then either 1) Clicking the button that looks like
{}
on the toolbar, or 2) usingCtrl+K
. Inline text can be formatted by surrounding it in backticks (the character to the left of the1
on most US keyboards), or `. Thanks. :)– Ken White
Nov 24 '11 at 5:27