public class JavaCopyFileProgram {
public static void main(String[] args)
{
File sourceFile = new File("F:/Study/Java/Java Programs/Factory Methods.txt");
File destFile = new File("D:/DestFile.txt");
FileInputStream inStream = null;
FileOutputStream outStream = null;
try
{
inStream = new FileInputStream(sourceFile);
outStream = new FileOutputStream(destFile);
byte[] buffer = new byte[1024];
int length;
while ((length = inStream.read(buffer)) != -1)
{
outStream.write(buffer, 0, length);
}
}
catch (IOException e)
{
e.printStackTrace();
}
finally
{
try
{
inStream.close();
outStream.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
System.out.println("Success");
}
}
어떻게 thw write() 메서드가 작동 하는지를 이해할 수 없습니까? 처음 호출 될 때 0 인덱스에서 바이트 배열의 길이로 코드를 작성하지만 두 번째 호출 할 때 이전 텍스트의 끝에 새 텍스트를 추가하는 방법은 무엇입니까? 다시 쓰기가 0으로 시작 색인으로 호출되므로 이전 내용을 대체해야합니다. 내가 뭔가 잘못 이해하면 도와 주시겠습니까?write (byte [], int, int) 메서드는 어떻게 작동합니까?