commit 0ba75af14755b9336ba99850640951a6d24154e1 Author: Jesus Date: Fri Oct 7 19:31:06 2022 +0200 Creating readme diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e1be76b --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +*.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..3d3ab27 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..55a8217 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f3d4380 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +## Preview + +![Running app](/cmd.gif") + diff --git a/cmd.gif b/cmd.gif new file mode 100644 index 0000000..ef20928 Binary files /dev/null and b/cmd.gif differ diff --git a/progress_bar.iml b/progress_bar.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/progress_bar.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/com/jesuspinar/main/Main.java b/src/com/jesuspinar/main/Main.java new file mode 100644 index 0000000..8d52ea3 --- /dev/null +++ b/src/com/jesuspinar/main/Main.java @@ -0,0 +1,68 @@ +package com.jesuspinar.main; + +import java.io.*; + +public class Main{ + public static void main(String[] arg) throws Exception { + copyFile("/Users/jesuspl/Documents/04DamPrac1/PRG/tema12/ficheros/nuevo.txt"); + } + private static boolean copyFile(String path){ + File inputFile = new File(path); + + try (FileInputStream fis = new FileInputStream(inputFile); + FileOutputStream fos = + new FileOutputStream(path+"cp"+ getExtension(inputFile)) + // fos.write(fis.readAllBytes()); + ){ + StringBuilder sb = new StringBuilder(); + long fileSize = inputFile.length(); + double onePercent = (double) 100/fileSize; + long count = 0; + int character ; + int i = 0; + while((character = fis.read()) != -1){ + count += character; + if (count >= onePercent) { + count = 0; + sb.append("#"); + System.out.print(++i +"% "+ sb ); + System.out.print("\r"); + Thread.sleep(100); + } + fos.write(character); + } + return true; + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } catch (IOException e) { + throw new RuntimeException(e); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + private static void progressPrint(){ + StringBuilder sb = new StringBuilder(); + + for (int i = 0 ; i <= 100 ; i++) { + sb.setLength(0); + for (int j = 0 ; j < i; j++) { + sb.append("#"); + } + try { + Thread.sleep(100); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + System.out.print("[" + String.format("%-100s", sb) + "] " + i + "%"); + System.out.print("\r"); + } + } + private static String getExtension(File file){ + String fileName = file.toString(); + int index = fileName.lastIndexOf('.'); + if(index > 0) { + return "." + fileName.substring(index + 1); + } + return ".dat"; + } +}