用java 写一个文件导入功能
时间: 2023-05-12 17:03:31 浏览: 47
好的,我可以为您提供一个简单的 Java 文件导入功能的代码示例:
```
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class FileImporter {
public static void main(String[] args) {
try {
File file = new File("example.txt");
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
System.out.println(line);
}
scanner.close();
} catch (FileNotFoundException e) {
System.out.println("文件未找到!");
e.printStackTrace();
}
}
}
```
这个程序可以读取名为 "example.txt" 的文件,并将其内容打印到控制台上。如果您需要导入其他类型的文件,只需更改文件名即可。希望这可以帮助到您!