|
-
Mar 1st, 2001, 06:50 PM
#1
Thread Starter
Dazed Member
Check out the java.Util.Array class. It has tons of fill methods that fill arrays.
-
Mar 1st, 2001, 07:34 PM
#2
Thread Starter
Dazed Member
This code would read strings from a .txt file and store
them in a String array. I just opted to print the contents
of the array right away. The code is limited in the respect that you would have to know how long the file
would be before you run it. or an Arrayoutofbounds
error will occur. But you get the idea....... still check out
the fill methods ive never used them but i think they would be easier to use.
import java.util.Arrays.*;
import java.io.*;
class Stringfiller{
public static void main(String[] args){
try {
BufferedReader buff = new BufferedReader(new FileReader("C:\\Java\\passwords.txt"));
String[] k = new String[8];
int i = 0;
while(true){
if(i >= 8) break;
String s = buff.readLine();
k[i] = s;
System.out.println(k[i]);
i++;
}
}catch(Exception e){System.err.println(e);}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|