我有一个程序,我不会随机读取 ARRAY 我没有程序错误但是在输出期间我有空值你能给我解决方案吗?
import java.io.FileInputStream;
import java.util.Properties;
import java.util.Random;
import javax.swing.JOptionPane;
public class ReadDB {
public static void main(String[] args) {
Properties prob = new Properties();
String word [] = new String [20] ;
try{
prob.load( new FileInputStream("words.txt"));
}catch(Exception e){
}
for(int i=1; i<6; i++){
String temp = prob.getProperty(""+i);
word[i] = temp;
Random ran = new Random ();
String Val = word[ran.nextInt(word.length)];
System.out.println(Val);
}
}
}