Re: Simple Java Question (reading text file of integer values)
- From: "Fahd Shariff" <fahdshariff@xxxxxxxxx>
- Date: 27 May 2005 07:58:20 -0700
Here is a quick hack. The lines are read into an arraylist which is
then copied to an array. The first integer is stored in arr[0] i.e.
integer k is stored in arr[k-1]. If thats not what you want, you can
fix it easily.
BufferedReader in = new BufferedReader(new
FileReader("data.txt")) ;
String line = "" ;
ArrayList nums = new ArrayList() ;
while((line = in.readLine())!=null){
int num ;
try{
num = Integer.parseInt(line) ;
nums.add(new Integer(num));
}catch(NumberFormatException e){}
}
int[] arr = new int[nums.size()] ;
for(int i = nums.size() ; --i>=0 ;){
arr[i] = ((Integer)nums.get(i)).intValue() ;
}
--
Fahd Shariff
"Let the code do the talking... "
.
- References:
- Simple Java Question (reading text file of integer values)
- From: TikkieTerug
- Simple Java Question (reading text file of integer values)
- Prev by Date: Re: Graphical overview of the java classes
- Next by Date: return more than one object within one method
- Previous by thread: Re: Simple Java Question (reading text file of integer values)
- Next by thread: New Java/J2EE support forum and blogs
- Index(es):
Relevant Pages
|