Browse Source

commit

master
yaroslav 2 years ago
commit
6a645effdd
9 changed files with 121 additions and 0 deletions
  1. +8
    -0
      .idea/.gitignore
  2. +6
    -0
      .idea/misc.xml
  3. +8
    -0
      .idea/modules.xml
  4. +6
    -0
      .idea/vcs.xml
  5. +11
    -0
      Serializable.iml
  6. BIN
      out/production/Serializable/Main.class
  7. BIN
      out/production/Serializable/Persona.class
  8. +58
    -0
      src/Main.java
  9. +24
    -0
      src/Persona.java

+ 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_19" default="true" project-jdk-name="19" 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$/Serializable.iml" filepath="$PROJECT_DIR$/Serializable.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>

+ 11
- 0
Serializable.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>

BIN
out/production/Serializable/Main.class View File


BIN
out/production/Serializable/Persona.class View File


+ 58
- 0
src/Main.java View File

@ -0,0 +1,58 @@
import java.io.*;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOException {
/*File file = new File("C:\\Users\\yaros\\Documents\\project\\serial.dat");
byte[] bytes;
ByteArrayInputStream bs= new ByteArrayInputStream(bytes); // bytes es el byte[]
ObjectInputStream is = new ObjectInputStream(bs);
ClaseSerializable unObjetoSerializable = (ClaseSerializable)is.readObject();
is.close();*/
boolean result = false;
File file = null;
String ruta;
Scanner sc = new Scanner(System.in);
while (result == false){
//ruta = sc.nextLine();
file = new File("C:\\Users\\yaros\\Documents\\project\\serial.dat");
if(file.exists()) {
FileReader fit = new FileReader(file);
BufferedReader br
= new BufferedReader(new FileReader(file));
// Declaring a string variable
String st;
// Condition holds true till
// there is character in a string
while ((st = br.readLine()) != null)
// Print the string
System.out.println(st);
//leerFichObject(file);
}
else
System.out.println("The file couldnt be found");
System.out.println("END");
}
}
public static void leerFichObject (File fichero) throws IOException {
Persona persona;
FileInputStream filein = new FileInputStream(fichero);
ObjectInputStream dataIS = new ObjectInputStream(filein);
try {
while (true) {
persona = (Persona) dataIS.readObject();
System.out.println("Nombre: "+persona.getNombre()+
" Edad: "+persona.getEdad());
}
} catch (EOFException error) {
//nada
} catch (ClassNotFoundException error) {
error.printStackTrace();
System.out.println(error.getMessage());
}
dataIS.close();
}
}

+ 24
- 0
src/Persona.java View File

@ -0,0 +1,24 @@
import java.io.Serializable;
public class Persona implements Serializable{
private String nombre;
private int edad;
public Persona(String nombre, int edad) {
this.nombre = nombre;
this.edad= edad;
}
public Persona() {
this.nombre=null;
}
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public int getEdad() {
return edad;
}
public void setEdad(int edad) {
this.edad = edad;
}
}

Loading…
Cancel
Save