Я хочу скопировать F: \ test в папку F: \ 123, чтобы у меня была папка F: \ 123 \ test.
В тестовой папке у меня есть 2 файла: входной и выходной .java
Но я не могу сделать, что ошибка: F \ 123 \ test \ output.java (система не может найти указанный путь)
Вот мой код:
Constant.fromPath = "F:\\test"
Constant.toPath = "F\\123\\test";
File source = new File(Constant.fromPath);
File destination = new File(Constant.toPath);
try
{
copyFolder(source, destination);
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
Вот функция copyFolder
public static void copyFolder(File srcFolder, File destFolder) throws IOException
{
if (srcFolder.isDirectory())
{
if (! destFolder.exists())
{
destFolder.mkdir();
}
String[] oChildren = srcFolder.list();
for (int i=0; i < oChildren.length; i++)
{
copyFolder(new File(srcFolder, oChildren[i]), new File(destFolder, oChildren[i]));
}
}
else
{
if(destFolder.isDirectory())
{
copyFile(srcFolder, new File(destFolder, srcFolder.getName()));
}
else
{
copyFile(srcFolder, destFolder);
}
}
}
public static void copyFile(File srcFile, File destFile) throws IOException
{
InputStream oInStream = new FileInputStream(srcFile);
OutputStream oOutStream = new FileOutputStream(destFile);
// Transfer bytes from in to out
byte[] oBytes = new byte[1024];
int nLength;
BufferedInputStream oBuffInputStream = new BufferedInputStream( oInStream );
while ((nLength = oBuffInputStream.read(oBytes)) > 0)
{
oOutStream.write(oBytes, 0, nLength);
}
oInStream.close();
oOutStream.close();
}
Пожалуйста, помогите мне исправить мою ошибку.