InputStream fileInputStream = getInputStream(sourceFileName);
OutputStream fileOutputStream = getOutputStream(destinationFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = fileInputStream.read(buffer)) > 0) {
fileOutputStream.write(buffer, 0, length);
package com.codegym.task.task09.task0929;
import java.io.*;
/*
Let's make the code do something useful!
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
try{
String sourceFileName = reader.readLine();
File f=new File(sourceFileName);
boolean exists = f.exists();
if(!exists)
{
sourceFileName = reader.readLine();
}
String destinationFileName = reader.readLine();
System.out.println(sourceFileName);
System.out.println(destinationFileName);
InputStream fileInputStream = getInputStream(sourceFileName);
OutputStream fileOutputStream = getOutputStream(destinationFileName);
byte[] buffer = new byte[1024];
int length;
while ((length = fileInputStream.read(buffer)) > 0) {
fileOutputStream.write(buffer, 0, length);
fileInputStream.close();
fileOutputStream.close();
}
}
catch(IOException e)
{
System.out.println("File does not exist.");
}
}
public static InputStream getInputStream(String fileName) throws IOException {
return new FileInputStream(fileName);
}
public static OutputStream getOutputStream(String fileName) throws IOException {
return new FileOutputStream(fileName);
}
}