我需要为学校制作这个课程 它首先提示用户输入txt文件,然后它会询问用户一个唯一的3字母代码,然后从代码中程序将读取txt文件并返回链接到该唯一代码的信息。
这是我到目前为止所做的:
import java.util.*;
import java.io.*;
public class assignA
{
public static void main (String [ ] args) throws IOException
{
Scanner keyboard = new Scanner (System.in);
System.out.print("Please enter the file name");
String filename = keyboard.nextLine ();
File f = new File (filename);
Scanner fin = new Scanner (f);
while(fin.hasNextLine());
{
String line = fin.nextLine ();
}
}
答案 0 :(得分:0)
我希望这会对你有所帮助。
import java.util.*;
import java.io.*;
public class assignA
{
public static void main (String [ ] args) throws IOException
{
Scanner keyboard = new Scanner (System.in);
System.out.print("Please enter the file name");
String filename = keyboard.nextLine ();
File f = new File (filename);
Scanner fin = new Scanner (f);
String code = "RXP"; //You can replace it with a scanner input
while(fin.hasNextLine());
{
String line = fin.nextLine();
String[] detail = line.split("#");
if (detail[0].equals(code)) {
System.out.println(detail[1] + detail[2]);
break;
}
}
}