954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to read numbers from text file

Hi, I want to know to rows and columns of numbers from a text file.
I do not want to read it as a string, but one number (including numbers with decimal) by itself. I tried using FileInputStream and DataInputStream, but I'm not really good at it. I don't know how to not read it as a double, and not a string.

Sunshineserene
Junior Poster
187 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
 

What might also work then in that case, is maybe just converting the string that you're getting to an int or what ever you want? As in:

myInt = Integer.parseInt(theStringThatYoureGetting);
Dean_Grobler
Posting Whiz in Training
222 posts since Aug 2010
Reputation Points: 72
Solved Threads: 9
 

Following Dean_Grobler's suggestion you may read each number as a string s, and then convert s into a decimal number in the type of double by the following line of code:

double d = Double.parseDouble(s);

or convert s into a decimal number in the type of float:

float f = Float.parseFloat(s);
tong1
Posting Whiz
358 posts since Jul 2010
Reputation Points: 34
Solved Threads: 72
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: