我正在尝试创建一个扫描器类,它应该输出一个包含以下信息的纯文本文件;
人名,地址,城市,电话号码,人名,地址,城市,电话号码,人名,地址,城市,电话号码,人名,地址,城市,电话号码,
我的分隔符是逗号。
每组数据都必须以二叉树的形式输出。首先以名称作为根节点,然后地址作为根节点,然后城市作为根节点,依此类推。
这是我创建的 Java 文件,它每次只输出“用法:java Scanner_Two phone.txt”+“文件位置”,下面没有树。谁能告诉我我哪里出错了。我还创建了一个 Entry 类、BinaryTreeNode 类和 Binary Tree 类。
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class Scanner_Two
{
private static void readFile(String TreeName)
{
try {
// Scanner input = new Scanner (new File("telephone.txt")).useDelimiter("\\s*,\\s*");
Scanner scanned = new Scanner(new File(TreeName));
scanned.useDelimiter
(System.getProperty("line.separator"));
while (scanned.hasNext())
{
parseLine(scanned.next());
}
scanned.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
private static void parseLine(String line)
{
Scanner lineScanner = new Scanner(line);
lineScanner.useDelimiter("\\s*,\\s*");
String rootnode = lineScanner.next();
String bone = lineScanner.next();
String btwo = lineScanner.next();
String bthree = lineScanner.next();
System.out.println("Name: " + rootnode + " Address: " + bone + ", City: " + btwo + ", Telephone Number: " + bthree);
}
public static void main(String[] args)
{
if(args.length != 1)
{
System.out.println("usage: java Scanner_Two Person.txt " + "file location");
System.exit(0);
}
readFile(args[0]);
}
}