| @ -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 | |||||
| @ -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 | |||||
| @ -0,0 +1,6 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <project version="4"> | |||||
| <component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK"> | |||||
| <output url="file://$PROJECT_DIR$/out" /> | |||||
| </component> | |||||
| </project> | |||||
| @ -0,0 +1,8 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <project version="4"> | |||||
| <component name="ProjectModuleManager"> | |||||
| <modules> | |||||
| <module fileurl="file://$PROJECT_DIR$/progress_bar.iml" filepath="$PROJECT_DIR$/progress_bar.iml" /> | |||||
| </modules> | |||||
| </component> | |||||
| </project> | |||||
| @ -0,0 +1,6 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <project version="4"> | |||||
| <component name="VcsDirectoryMappings"> | |||||
| <mapping directory="$PROJECT_DIR$" vcs="Git" /> | |||||
| </component> | |||||
| </project> | |||||
| @ -0,0 +1,4 @@ | |||||
| ## Preview | |||||
|  | |||||
| @ -0,0 +1,11 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <module type="JAVA_MODULE" version="4"> | |||||
| <component name="NewModuleRootManager" inherit-compiler-output="true"> | |||||
| <exclude-output /> | |||||
| <content url="file://$MODULE_DIR$"> | |||||
| <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | |||||
| </content> | |||||
| <orderEntry type="inheritedJdk" /> | |||||
| <orderEntry type="sourceFolder" forTests="false" /> | |||||
| </component> | |||||
| </module> | |||||
| @ -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"; | |||||
| } | |||||
| } | |||||