Guest User

Untitled

a guest
Jan 21st, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. public static void binaryStream() throws IOException {
  2.  
  3. try {
  4.  
  5. FileInputStream inputStream = new FileInputStream(new File("Untitled.png"));
  6. FileOutputStream outputStream = new FileOutputStream(new File("Untitled-copied.png"));
  7.  
  8. int data;
  9. while ((data = inputStream.read()) >= 0) {
  10. outputStream.write(data);
  11. }
  12.  
  13. outputStream.write(data);
  14.  
  15. inputStream.close();
  16. outputStream.close();
  17.  
  18. } catch (FileNotFoundException e) {
  19. System.out.println("Error");
  20. } catch (IOException e) {
  21. System.out.println("Error");
  22. }
  23.  
  24. }
  25.  
  26. import java.io.*;
  27.  
  28. public class BinaryStream {
  29. public static void binaryStream(String file1, String file2) throws Exception
  30. {
  31. File sourceFile = new File(file1);
  32. try(FileInputStream inputStream = new FileInputStream(sourceFile)) {
  33. try(FileOutputStream outputStream = new FileOutputStream(new File(file2))) {
  34. long lenOfFile = sourceFile.length();
  35.  
  36. long currentBytesWritten = 0;
  37. int data;
  38. while ((data = inputStream.read()) != -1) {
  39. outputStream.write(data);
  40. currentBytesWritten += 1;
  41. System.out.printf("%2.2f%%%n", 100*((double)currentBytesWritten)/((double)lenOfFile));
  42. }
  43. }
  44. }
  45. }
  46.  
  47. public static void main(String args[]) throws Exception {
  48. binaryStream("Untitled.png", "Untitled-copied.png");
  49. }
  50. }
  51.  
  52. 0,06%
  53. // removed data
  54. 99,89%
  55. 99,94%
  56. 100,00%
Add Comment
Please, Sign In to add comment