Java
InputStream inStream =
new
FileInputStream(
new
File(
"...."));
byte
[] buffer =
new
byte
[
inStream
.available()];
inStream
.read(buffer);
File outFile =
new
File(
"........."
);
OutputStream outStream =
new
FileOutputStream(
outFile
);
outStream.write(buffer);
Java with buffer
InputStream inStream =
new
FileInputStream(
new
File(
"...."));
byte
[] buffer =
new
byte
[
inStream
.available()];
inStream
.read(buffer);
File outFile =
new
File(
"........."
);
OutputStream outStream =
new
FileOutputStream(
outFile
);
byte
[] buffer =
new
byte
[
1024
];
int
bytesRead;
while
((bytesRead = inStream.read(buffer)) != -
1
) {
outStream.write(buffer,
0
, bytesRead);
}
IOUtils.closeQuietly(initialStream);
I
OUtils.closeQuietly(outStream);
Java 8 - the easy way
InputStream inStream =
new
FileInputStream(
new
File(
"...."));
byte
[] buffer =
new
byte
[
inStream
.available()];
inStream
.read(buffer);
File outFile =
new
File(
"........."
);
java.nio.file.Files.copy(
inStream,
outFile
.toPath(),
StandardCopyOption.REPLACE_EXISTING);
Apache Commons
InputStream inStream =
new
FileInputStream(
new
File(
"...."));
byte
[] buffer =
new
byte
[
inStream
.available()];
inStream
.read(buffer);
File outFile =
new
File(
"........."
);
FileUtils.copyInputStreamToFile(inStream,
outFile
);
Commenti
Posta un commento