Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions 3 Seminar 5/code/Project 5/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions 6 Seminar 5/code/Project 5/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions 8 Seminar 5/code/Project 5/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions 6 Seminar 5/code/Project 5/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions 11 Seminar 5/code/Project 5/Project 5.iml
Original file line number Diff line number Diff line change
@@ -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>
1 change: 1 addition & 0 deletions 1 Seminar 5/code/Project 5/file1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Some text here
Binary file added BIN +127 Bytes Seminar 5/code/Project 5/myfile.txt
Binary file not shown.
Binary file not shown.
Binary file not shown.
74 changes: 74 additions & 0 deletions 74 Seminar 5/code/Project 5/src/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import java.io.*;

public class Main {
private static final String FILE_NAME = "myfile.txt";

public static void main(String[] args) {
// Student s1 = new Student();
// s1.setFacultyNumber("123124");
// s1.setName("Bai Ivan");
// s1.setEmail("BaiIvan@abv.bg");

Student s2 = deserializeStudent();
System.out.println(s2.getEmail());
}

public static void externalizeTeacher(Teacher teacher) {
try (FileOutputStream fileOutput = new FileOutputStream(FILE_NAME);
ObjectOutputStream objectOut = new ObjectOutputStream(fileOutput);) {
objectOut.writeObject(teacher);
} catch (IOException e) {
e.printStackTrace();
}
}

public static Student deserializeStudent() {
Student result = null;
try (FileInputStream fileOutput = new FileInputStream(FILE_NAME);
ObjectInputStream objectOut = new ObjectInputStream(fileOutput);) {
result = (Student)objectOut.readObject();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}

return result;
}

public static void serializeStudent(Student student) {
try (FileOutputStream fileOutput = new FileOutputStream(FILE_NAME);
ObjectOutputStream objectOut = new ObjectOutputStream(fileOutput);) {
objectOut.writeObject(student);
} catch (IOException e) {
e.printStackTrace();
}
}

public static void writeToAFile(String fileName) {
try(BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(fileName))) {
String fileContent = "Some text here";
bufferedWriter.write(fileContent);
} catch (IOException e) {
// Exception handling​
}
}

public static String readStringFromAFile(String fileName) {
String result = "";
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(fileName))) {
String line = bufferedReader.readLine();
while (line != null) {
System.out.println("I am from 25: " + line);
result += line;
line = bufferedReader.readLine();
}
} catch (FileNotFoundException e) {
// Exception handling
} catch (IOException e) {
// Exception handling
}

return result;
}
}
31 changes: 31 additions & 0 deletions 31 Seminar 5/code/Project 5/src/Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import java.io.Serializable;

public class Student implements Serializable {
private String facultyNumber;
private String name;
private String email;

public String getFacultyNumber() {
return facultyNumber;
}

public void setFacultyNumber(String facultyNumber) {
this.facultyNumber = facultyNumber;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}
}
35 changes: 35 additions & 0 deletions 35 Seminar 5/code/Project 5/src/Teacher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;

public class Teacher implements Externalizable {
private String name;
private boolean isStupid;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public boolean isStupid() {
return isStupid;
}

public void setStupid(boolean stupid) {
isStupid = stupid;
}

@Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeUTF(this.getName());
}

@Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
this.setName(in.readUTF());
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.