한 디렉토리에서 다른 디렉토리로 파일을 이동해야합니다.자바에서 큰 파일 이동
속성 파일을 사용하고 있습니다. 따라서 원본 및 대상 경로는 속성 파일에 저장됩니다. 속성 리더 클래스도 있습니다.
제 소스 디렉토리에 많은 파일이 있습니다. 하나의 파일이 완료되면 다른 디렉토리로 이동해야합니다.
파일 크기가 500MB 이상입니다.
import java.io.File;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import static java.nio.file.StandardCopyOption.*;
public class Main1
{
public static String primarydir="";
public static String secondarydir="";
public static void main(String[] argv)
throws Exception
{
primarydir=PropertyReader.getProperty("primarydir");
System.out.println(primarydir);
secondarydir=PropertyReader.getProperty("secondarydir");
File dir = new File(primarydir);
secondarydir=PropertyReader.getProperty("secondarydir");
String[] children = dir.list();
if (children == null)
{
System.out.println("does not exist or is not a directory");
}
else
{
for (int i = 0; i < children.length; i++)
{
String filename = children[i];
System.out.println(filename);
try
{
File oldFile = new File(primarydir,children[i]);
System.out.println("Before Moving"+oldFile.getName());
if (oldFile.renameTo(new File(secondarydir+oldFile.getName())))
{
System.out.println("The file was moved successfully to the new folder");
}
else
{
System.out.println("The File was not moved.");
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
System.out.println("ok");
}
}
}
내 코드가 파일을 올바른 경로로 이동하지 않습니다.
이 파일은 B 드라이브에 있어야 내 재산 파일
primarydir=C:/Desktop/A
secondarydir=D:/B
enter code here
입니다. 수행하는 방법? 어느 누구든지 나를 도울 수 있습니다 .. !!
'FileChannel.transferTo()의
Files.move()
를 사용할 수'당신이 필요로 될 수 있습니다. –당신의 디렉토리가''\ "'로 끝나야한다고 생각합니다. 이런 식으로'dir + file.getName()'은 유효한 경로를 생성합니다. –
제공 한 코드에서 secondarydir이 '\'로 끝나야합니다. primarydir의 경우에는 필요가 없습니다. – robin