Browse Source

Creating readme

main
Jesus 2 years ago
commit
0ba75af147
9 changed files with 140 additions and 0 deletions
  1. +29
    -0
      .gitignore
  2. +8
    -0
      .idea/.gitignore
  3. +6
    -0
      .idea/misc.xml
  4. +8
    -0
      .idea/modules.xml
  5. +6
    -0
      .idea/vcs.xml
  6. +4
    -0
      README.md
  7. BIN
      cmd.gif
  8. +11
    -0
      progress_bar.iml
  9. +68
    -0
      src/com/jesuspinar/main/Main.java

+ 29
- 0
.gitignore View File

@ -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

+ 8
- 0
.idea/.gitignore View File

@ -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

+ 6
- 0
.idea/misc.xml View File

@ -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>

+ 8
- 0
.idea/modules.xml View File

@ -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>

+ 6
- 0
.idea/vcs.xml View File

@ -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>

+ 4
- 0
README.md View File

@ -0,0 +1,4 @@
## Preview
![Running app](/cmd.gif")

BIN
cmd.gif View File

Before After
Width: 600  |  Height: 404  |  Size: 926 KiB

+ 11
- 0
progress_bar.iml View File

@ -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>

+ 68
- 0
src/com/jesuspinar/main/Main.java View File

@ -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";
}
}

Loading…
Cancel
Save