Check out the java.Util.Array class. It has tons of fill methods that fill arrays.
Printable View
Check out the java.Util.Array class. It has tons of fill methods that fill arrays.
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);}
}
}