Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void binaryStream() throws IOException {
- try {
- FileInputStream inputStream = new FileInputStream(new File("Untitled.png"));
- FileOutputStream outputStream = new FileOutputStream(new File("Untitled-copied.png"));
- int data;
- while ((data = inputStream.read()) >= 0) {
- outputStream.write(data);
- }
- outputStream.write(data);
- inputStream.close();
- outputStream.close();
- } catch (FileNotFoundException e) {
- System.out.println("Error");
- } catch (IOException e) {
- System.out.println("Error");
- }
- }
- import java.io.*;
- public class BinaryStream {
- public static void binaryStream(String file1, String file2) throws Exception
- {
- File sourceFile = new File(file1);
- try(FileInputStream inputStream = new FileInputStream(sourceFile)) {
- try(FileOutputStream outputStream = new FileOutputStream(new File(file2))) {
- long lenOfFile = sourceFile.length();
- long currentBytesWritten = 0;
- int data;
- while ((data = inputStream.read()) != -1) {
- outputStream.write(data);
- currentBytesWritten += 1;
- System.out.printf("%2.2f%%%n", 100*((double)currentBytesWritten)/((double)lenOfFile));
- }
- }
- }
- }
- public static void main(String args[]) throws Exception {
- binaryStream("Untitled.png", "Untitled-copied.png");
- }
- }
- 0,06%
- // removed data
- 99,89%
- 99,94%
- 100,00%
Add Comment
Please, Sign In to add comment