构造函数文件(路径)未定义



我在这段代码中有一个错误:

来源:

System.out.println("Load");
Path path = Paths.get("BillboardHot100.csv");
Path textpath = path;
user1.User_Playlist.load(textpath);
user1.User_Playlist.shuffle(40);
Stream.Users.add(user1);
Stream.userList();

尝试:

public void load(Path textpath){
if (textpath != null){
try {
File playlistFile = new File(textpath);
Scanner fileScanner = new Scanner(playlistFile);
System.out.println("Processing playlist file " + playlistFile + ":");

我在File playlistFile = new File(textpath);上遇到错误

错误显示:The constructor File(Path) is undefined

我需要帮助修复这个错误

java.io.File没有Path类型的构造函数。您可以将中的textpath转换为String

File playlistFile = new File(textpath.toString);

或者您也可以使用Scanner scan = new Scanner(textpath);

最新更新