我有一个文本文件:-
2,5,6,10,5,30
我正在尝试使用此代码来读取文件:-
package str;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
public class getall {
/**
* @param args
*/
public static void main(String args[])
{
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("D://Workspace_J/getstr/src/str/activity.text");
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
for(int a =1;a<3;a = a+1)
{
System.out.println("get value from the file randomly");
}
}
}
我可以成功读取文件内容,
但我想使用 for 循环读取随机值......
我该怎么做?