File copy
public void fileCopy(String file,String target){
try(InputStream inputStream = new FileInputStream(file)){
try(OutputStream outputStream = new FileOutputStream (target)){
byte [] buffer = new byte[4096];
int bytesToRead;
while((bytesToRead=inputStream.read(buffer))!=-1){
outputStream.write(buffer,0,bytesToRead);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void copyNio(String file,String target){
try(FileInputStream inputStream = new FileInputStream(file)){
try(FileOutputStream outputStream = new FileOutputStream(target)){
FileChannel inChannel = inputStream.getChannel();
FileChannel oUTChannel = outputStream.getChannel();
java.nio.ByteBuffer buffer = java.nio.ByteBuffer.allocate(4096);
while(inChannel.read(buffer)!=-1){
buffer.flip();
oUTChannel.write(buffer);
buffer.clear();
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}