| @ -0,0 +1,10 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <classpath> | |||
| <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"> | |||
| <attributes> | |||
| <attribute name="module" value="true"/> | |||
| </attributes> | |||
| </classpathentry> | |||
| <classpathentry kind="src" path="src"/> | |||
| <classpathentry kind="output" path="bin"/> | |||
| </classpath> | |||
| @ -0,0 +1,17 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <projectDescription> | |||
| <name>MiCopyFicheros</name> | |||
| <comment></comment> | |||
| <projects> | |||
| </projects> | |||
| <buildSpec> | |||
| <buildCommand> | |||
| <name>org.eclipse.jdt.core.javabuilder</name> | |||
| <arguments> | |||
| </arguments> | |||
| </buildCommand> | |||
| </buildSpec> | |||
| <natures> | |||
| <nature>org.eclipse.jdt.core.javanature</nature> | |||
| </natures> | |||
| </projectDescription> | |||
| @ -0,0 +1,2 @@ | |||
| eclipse.preferences.version=1 | |||
| encoding/<project>=UTF-8 | |||
| @ -0,0 +1,14 @@ | |||
| eclipse.preferences.version=1 | |||
| org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | |||
| org.eclipse.jdt.core.compiler.codegen.targetPlatform=17 | |||
| org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | |||
| org.eclipse.jdt.core.compiler.compliance=17 | |||
| org.eclipse.jdt.core.compiler.debug.lineNumber=generate | |||
| org.eclipse.jdt.core.compiler.debug.localVariable=generate | |||
| org.eclipse.jdt.core.compiler.debug.sourceFile=generate | |||
| org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | |||
| org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled | |||
| org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | |||
| org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning | |||
| org.eclipse.jdt.core.compiler.release=enabled | |||
| org.eclipse.jdt.core.compiler.source=17 | |||
| @ -0,0 +1,36 @@ | |||
| # README.md | |||
| ## Titulo | |||
| MyCopy Ficheros | |||
| ## Autor | |||
| Alejandro Javier Albus 2CFGS DAM | |||
| ## Enunciado | |||
| ACTIVIDAD 06 : Crea un programa Java MiCopy que copie un archivo. | |||
| Por ejemplo “MiCopy FicheroOrigen.dat FicheroDestino.dat. El programa tendrá que mostrar por pantalla el tanto | |||
| por cien que lleva realizada de la copia y deberá también mostrar algún tipo de animación (similar a wget). | |||
| Cuando termine la copia se mostrará un mensaje de fin de la copia. | |||
| ## Uso | |||
| Debe introducir en los atributos del programa el archivo a copiar (IN) y el destino de dicho archivo (OUT). | |||
| Dicho archivo se copiará integramente. | |||
| ## Ejemplo de ejecución | |||
| Los cuadrados iran apareciendo desde 0. | |||
| <pre> | |||
| <code> | |||
| > Empezando copia ... | |||
| [■■■■■■■■■■] 100% | |||
| + Se ha finalizado la copia correctamente | |||
| </code> | |||
| </pre> | |||
| ## Dependencias | |||
| Uso de librerias externas: | |||
| * java.io.* | |||
| ## Licencia | |||
| Uso libre | |||
| @ -0,0 +1,76 @@ | |||
| package MiCopyFicheros; | |||
| import java.io.*; | |||
| public class MiCopyFicheros { | |||
| public static void main(String[] args) throws IOException { | |||
| //Tenemos los directorios y ficheros a copiar (origen) | |||
| final String directory = "C:\\Users\\jandr\\Desktop\\Acceso a datos\\Container Ficheros\\"; | |||
| File f = new File(directory + "Fich_Origen_0410.bin"); | |||
| //Creamos los FIS y tambien decimos a donde mandar el nuevo archivo | |||
| FileInputStream in = new FileInputStream(f); | |||
| FileOutputStream out = new FileOutputStream(directory + "Fich_Destino_0410"); | |||
| //Empezamos la copia, si no esta vacio - null | |||
| if (in != null) { | |||
| System.out.println("\n> Empezando copia ..."); | |||
| for (int i = 0; i <= 200; i = i + 20) { | |||
| //Invocamos al metodo | |||
| progressPercentage(i, 200); | |||
| //Ralentizamos el output | |||
| try { | |||
| Thread.sleep(1000); | |||
| } catch (InterruptedException e) { | |||
| throw new RuntimeException(e); | |||
| } | |||
| } | |||
| System.out.println("\n+ Se ha finalizado la copia correctamente"); | |||
| } | |||
| //Cerramos los lectores | |||
| in.close(); | |||
| out.close(); | |||
| } | |||
| /** | |||
| * Muestra el porcentaje del progreso [0/100%] | |||
| */ | |||
| private static void progressPercentage(int remain, int total) { | |||
| //Si lo restante supera al total, lanzaremos excepcion | |||
| if (remain > total) | |||
| throw new IllegalArgumentException(); | |||
| //Generamos los atributos in-class | |||
| int maxSize = 10, remaining = calcProgress(remain, total, maxSize); | |||
| char notDone = '-'; | |||
| String done = "■", bare = new String(new char[maxSize]).replace('\0', notDone) + "]", bareDone = "[", | |||
| bareRemain = bare.substring(remaining, bare.length());; | |||
| for (int i = 0; i < remaining; i++) | |||
| bareDone += done; | |||
| //Imprimimos el resultado | |||
| System.out.print("\r" + bareDone + bareRemain + " " + remaining * 10 + "%"); | |||
| } | |||
| /** | |||
| * Calculo del progreso | |||
| */ | |||
| private static int calcProgress(int remain, int total, int maxBareSize) { | |||
| return ((100 * remain) / total) / maxBareSize; | |||
| } | |||
| } | |||