[英]How to read random line from remote txt file?
I can not understand how to make a random string
was taken from a remote file Now i have this construct. 我不明白如何从远程文件中提取随机string
。现在,我有了这个结构。 It show me with Toast first line of file. 它以Toast文件的第一行显示给我。 How can i read a random line? 我如何读取随机行?
public void bClick(View view) throws IOException {
String test = new Scanner(new URL("http://www.somesite.us/1.txt").openStream()).
nextLine();
Toast.makeText(this, test, Toast.LENGTH_SHORT).show();
}
You can try to call nextLine() until you reach the line that you want 您可以尝试调用nextLine()直到到达所需的行
Scanner scanner = new Scanner(new URL("http://www.somesite.us/1.txt").openStream())
while (scanner.hasNextLine()) {
String test = scanner.nextLine();
Toast.makeText(this, test, Toast.LENGTH_SHORT).show();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.