如何在用户的AppData目录中创建目录和文件? [英] How do I create directories and files within the user's AppData directory?
本文介绍了如何在用户的AppData目录中创建目录和文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以,我正在创建一个游戏,需要创建目录来存储所有用户的数据并保存和诸如此类的东西。正如您所看到的,我需要在名为[WarDungeon]的用户的Application Data文件夹中创建一个文件夹,在那里,我将存储其他文件夹,例如level,bin,sprite等。
So, I'm creating a game and need to create directories to store all the user's data and saves and whatnot. As you can see, I need to create a folder in the Application Data folder of the user called, "[WarDungeon]", and there, I will store other folders for such data like levels, the bin, sprites, etc.
我对使用Mac OS和Linux不太感兴趣,因为我想让%appdata%文件夹与Windows一起使用。
I am not too interested in working with Mac OS and Linux as I want to get the %appdata% folder working with Windows to begin with.
这是我的代码:
public FileManage() {
gamePath = System.getenv("APPDATA") + "[WarDungeon]";
gameLevelPath = System.getProperty("user.home") + "\\Local Settings\\ApplicationData\\[WarDungeon]\\level";
gameBinPath = System.getProperty("user.home") + "\\Local Settings\\ApplicationData\\[WarDungeon]\\bin";
File createDir1 = new File(gamePath);
createDir1.mkdir();
System.out.println("First test passed.");
if (createDir1.exists() == true) {
System.out.println("First directory created!");
}
}
如何解决此问题?
提前致谢:)
推荐答案
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
这篇关于如何在用户的AppData目录中创建目录和文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文