gpt4 book ai didi

java - java中的绝对路径直接到桌面,即使在不同的计算机上

转载 作者:行者123 更新时间:2023-12-01 18:04:41 28 4
gpt4 key购买 nike

即使在不同的计算机上,我如何才能自动将 BufferReader Path 定向到桌面。 '''BufferedReader in = new BufferedReader(new FileReader("C:\Users\.....\".txt"));''

最佳答案

你可以使用

  public static void main(String[] args) throws IOException {
String path = System.getProperty("user.home") + "/Desktop/test.txt";
BufferedReader in = new BufferedReader(new FileReader(path));
String line;
while ((line = in.readLine()) != null) {
System.out.println("line = " + line);

}
in.close();
}

获取桌面路径并从中读取文本文件

关于java - java中的绝对路径直接到桌面,即使在不同的计算机上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60577386/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com