0
在用戶文件夾中創建文件的最佳方式是什麼?應用程序保存在共享位置的服務器上,但文件必須存儲在他們使用的計算機中。他們從不同的計算機運行該應用程序,但都安裝了Windows(xp和7)。如果應用程序從服務器運行,則Windows用戶文件夾
我現在的方法是這樣的:
public static String getDocumentsFolder() {
String myDocuments = null;
try {
Process p = Runtime.getRuntime().exec("reg query \"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\" /v personal");
if (p.waitFor()==0) {
InputStream in = p.getInputStream();
byte[] b = new byte[in.available()];
in.read(b);
in.close();
myDocuments = new String(b);
myDocuments = myDocuments.split("\\s\\s+")[4];
} else {
//nothing for now...
}
myDocuments+="\\MyApp";
new File(myDocuments).mkdirs();
} catch(Exception e) {
ErrorHandler.handle(e);
}
return myDocuments;
}
幫助深表感謝!謝謝