我有一个微服务,并且同一服务的docker映像正在一个EC2实例中运行,我想通过按我的要求访问该服务URL在同一EC2内创建新文件夹。
那么,那有可能吗?
这是我用来创建文件夹并将其复制粘贴到新创建的文件夹中的代码(在我的本地系统中工作正常,但在EC2环境中不能正常工作)
public static void copyFolder(File sourceFolder, File destinationFolder) throws IOException
{
//Check if sourceFolder is a directory or file
//If sourceFolder is file; then copy the file directly to new location
if (sourceFolder.isDirectory())
{
//Verify if destinationFolder is already present; If not then create it
if (!destinationFolder.exists())
{
destinationFolder.mkdir();
//System.out.println("Directory created :: " + destinationFolder);
}
//Get all files from source directory
String files[] = sourceFolder.list();
//Iterate over all files and copy them to destinationFolder one by one
for (String file : files)
{
File srcFile = new File(sourceFolder, file);
File destFile = new File(destinationFolder, file);
//Recursive function call
copyFolder(srcFile, destFile);
}
}
else
{
//Copy the file content from one place to another
Files.copy(sourceFolder.toPath(), destinationFolder.toPath(), StandardCopyOption.REPLACE_EXISTING);
// System.out.println("File copied :: " + destinationFolder);
}
}
这是我尝试通过提供EC2实例文件夹的路径来调用上述方法创建文件夹并复制粘贴内容的方法。由于“ /” 是EC2实例的根。
File sourceFolder = new File("/storenew/sdkThemes/muvinew");
File destinationFolder = new File("/storenew/Themes/"+storeDetails.getSubDomainName());
StoreUtil.copyFolder(sourceFolder, destinationFolder);