Results 1 to 4 of 4
Thread: Arrays and File Reading
- 08-12-2009, 03:53 PM #1
Member
- Join Date
- Jul 2009
- Posts
- 11
- Rep Power
- 0
Arrays and File Reading
It is me again and I can once again use a little help. My little learning project is going along very well but I am once again stuck....
What I want to do now is create an array and use items from a txt file to fill the array.
If I remember correctly, I need to create a FileInputStream linking to the file and then use BufferedReader to read it in... This is kind of what I did.
I can't cut and paste right now as I am coding on one computer (not connected to the network) and posting from one that is. (Long Story)....Java Code:try { FileInputStream interestIn = new FileInputStream("interest.rtf); BufferedReader interestOut = new BufferedReader(new InputStreamReader(interestIn)); for (int j; j < interestRateArray.length; j++) { interestRateArray[j] = interestOut.readLine(); } interestOut.close();
Basically what I am trying to do is take an array that I had created manually in the code and make it go out and pull the values from a file into the array.
Should I create new method for this?
Like before, I also don't want to post the code up as this is an active universites project (UoP) that I am playing with for the fun of it. Any help is appreciated and if you could point me in the right direction please let me know.
- 08-12-2009, 04:12 PM #2
Member
- Join Date
- Jul 2009
- Posts
- 11
- Rep Power
- 0
OK, to add to the above, I managed to get my code cleaned up with no errors.
:)
What I am getting now is that the file can't be found when I run that application. I have tried the total path and the local path with no luck. I am on a Mac, so I wonder if there is something that I am missing.
- 08-12-2009, 05:05 PM #3
catch the "FileNotFoundException
1.Either give the above exception in try-catch or use throws
2.Check whether file exist on the same directory where ur java class is located because u have not specified the path and directly giving the file.
3.If u give path put "/" for location not "\"Ramya:cool:
- 08-12-2009, 05:28 PM #4
Member
- Join Date
- Jul 2009
- Posts
- 11
- Rep Power
- 0
Thanks!
I think that I got that figured out but I am now getting another error instead of the file not found one.
Basically I think that it is trying to read the file but something is happeneing. I created an RTF file in my directory and I think that it is now finding it as I am getting a different error.
Can't open input server /Library/InputManagers/MultiClutchInputManager.bundle
It looks like something about Floating Decimal....
I did get rid of the try and catch and declared the exception and the beginning of the method.
Here is what I did...
My "interest" file contains three decimal numbers seperated by a return.Java Code:String [] interestRateArray = new String [3]; FileInputStream interestIn = new FileInputStream("/Users/Will/.../interest.rtf"); BufferedReader interestOut = new BufferedReader(new InputStreamReader(interestIn)); for (int j; j < interestRateArray.length; j++) { interestRateArray[j] = interestOut.readLine(); } interestOut.close();
My question is, will this work or am I off base here? I don't get any compiling errors but it does crash.
Just so you know, after I load up the array, I am pulling the number from the array position and then using parse to get it to a double so that I can use it.
Similar Threads
-
[SOLVED] how to reading binary file and writing txt file
By tOpach in forum New To JavaReplies: 3Last Post: 05-09-2009, 11:31 PM -
Input data from file to arrays problem
By PVL268 in forum New To JavaReplies: 18Last Post: 03-16-2009, 05:05 AM -
Right use of file reading ?
By jurka in forum New To JavaReplies: 3Last Post: 08-27-2008, 08:16 PM -
Making arrays by reading user input
By apfroggy0408 in forum New To JavaReplies: 23Last Post: 04-30-2008, 01:23 AM -
Problem with Sequential File and Arrays
By rhivka in forum New To JavaReplies: 8Last Post: 07-30-2007, 09:03 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks