java初学者在这里!
我有一个可以在桌面上创建大量文件夹的程序。 创建的文件夹,名称存储为字符串。
我的问题是: 使用文件编写器时,如何将包含刚创建的“文件夹名称”的字符串传递到显示传递到文件编写器的文件夹位置的字符串中?
示例
String folderpath = System.getProperty("user.home") + "\\Desktop\\"+"textfile.txt"+"";
传递“桌面”的位置并在那里创建一个名为textfile.txt的文件
我要求将textfile.txt创建到我创建的文件夹中。
以这种方式执行此操作:“ \ Desktop \ aFolder \”无法正常工作,因为我将创建多个具有不同名称的文件夹。
我希望当我存储刚创建的文件夹的名称时,可以以某种方式将其传递给此字符串吗?
谢谢
答案 0 :(得分:0)
String dynamicFoldarName="some-folder-name"; // set it programmatically
String parentPath =System.getProperty("user.home") + File.separator+"Desktop";
String childPath = dynamicFoldarName;
String fileName= "textfile.txt";
String folderpath = parentPath+ File.separator+childPath+File.separator+fileName;