Java如何打印文件名?

发布于 2025-02-01 01:15:51 字数 661 浏览 4 评论 0原文

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class hello {
    public static void main(String[] args) {
        try {
            FileReader fin = new FileReader("c:\\windows\\system.ini");
            Scanner scn = new Scanner(fin);
            while (scn.hasNext()) {
                String tmp = scn.nextLine();
                System.out.println(tmp);
            }
            fin.close();
            scn.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

如何打印c:\ windows \ system.ini(path?file?name)。 有什么方法可以打印道路吗?

import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class hello {
    public static void main(String[] args) {
        try {
            FileReader fin = new FileReader("c:\\windows\\system.ini");
            Scanner scn = new Scanner(fin);
            while (scn.hasNext()) {
                String tmp = scn.nextLine();
                System.out.println(tmp);
            }
            fin.close();
            scn.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

how can i print c:\windows\system.ini (path? file?name).
Is there any way to print the path?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

救赎№ 2025-02-08 01:15:51

检查一下:

        try {
            File file = new File("c:\\windows\\system.ini");
            FileReader fileReader = new FileReader(file);
            System.out.println(file.getName());
            System.out.println(file.getPath());
            Scanner scn = new Scanner(fileReader);
            while (scn.hasNext()) {
                String tmp = scn.nextLine();
                System.out.println(tmp);
            }
            fileReader.close();
            scn.close();
        }catch (Exception e) {

        }

您可以使用文件,然后将其传递给FileReader。

Check this out:

        try {
            File file = new File("c:\\windows\\system.ini");
            FileReader fileReader = new FileReader(file);
            System.out.println(file.getName());
            System.out.println(file.getPath());
            Scanner scn = new Scanner(fileReader);
            while (scn.hasNext()) {
                String tmp = scn.nextLine();
                System.out.println(tmp);
            }
            fileReader.close();
            scn.close();
        }catch (Exception e) {

        }

you can use File then pass it to FileReader.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文