gpt4 book ai didi

java - eclipse 中的文件输出流。相对路径

转载 作者:行者123 更新时间:2023-11-29 04:29:34 27 4
gpt4 key购买 nike

有没有办法在 eclipse 中保存 .txt 文件?

目前我在做:

FileOutputStream fout = new FileOutputStream("C:\\Users\\xxxx\\mytxtfile.txt", false);

我希望它位于项目的 eclipse 文件夹中,而不是绝对路径。

最佳答案

试试这个

FileOutputStream fout = new FileOutputStream("mytxtfile.txt", false);

如果你想在项目根目录中使用一个文件夹,我推荐这个:

File root = new File("yourfolder");
root.mkdir(); //this makes sure the folder exists
File file = new File(root,"mytextfile.txt");
FileOutputStream fout = new FileOutputStream(file, false);

获取 eclipse 3.3 的 eclipse 安装位置(我不知道你为什么要这样做,但仍然)System.getProperty("eclipse.home.location");

对于较新的 eclipse 版本我真的不知道。

关于java - eclipse 中的文件输出流。相对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44343304/

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