Не могу понять почему не пропускает Валя.
package com.javarush.task.task20.task2004;
import java.io.*;
/*
Читаем и пишем в файл статики
*/
public class Solution {
public static void main(String[] args) {
//you can find your_file_name.tmp in your TMP directory or adjust outputStream/inputStream according to your file's actual location
//вы можете найти your_file_name.tmp в папке TMP или исправьте outputStream/inputStream в соответствии с путем к вашему реальному файлу
try {
File yourFile = File.createTempFile("your_file_name", null);
OutputStream outputStream = new FileOutputStream(args[0]);
InputStream inputStream = new FileInputStream(args[0]);
ClassWithStatic classWithStatic = new ClassWithStatic();
classWithStatic.i = 3;
classWithStatic.j = 4;
classWithStatic.save(outputStream);
outputStream.flush();
ClassWithStatic loadedObject = new ClassWithStatic();
loadedObject.staticString = "something";
loadedObject.i = 6;
loadedObject.j = 7;
loadedObject.load(inputStream);
System.out.println(loadedObject.equals(classWithStatic));
//here check that the classWithStatic object is equal to the loadedObject object - проверьте тут, что classWithStatic и loadedObject равны
outputStream.close();
inputStream.close();
} catch (IOException e) {
//e.printStackTrace();
System.out.println("Oops, something is wrong with my file");
} catch (Exception e) {
//e.printStackTrace();
System.out.println("Oops, something is wrong with the save/load method");
}
}
public static class ClassWithStatic {
public static String staticString = "This is a static test string";
public int i;
public int j;
public void save(OutputStream outputStream) throws Exception {
PrintStream stream = new PrintStream(outputStream);
stream.println(staticString);
stream.println(i);
stream.println(j);
stream.flush();
//implement this method - реализуйте этот метод
}
public void load(InputStream inputStream) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String s;
String result = "";
while ((s = reader.readLine()) != null){
result += s + "\r\n";
}
reader.close();
if (result != null) {
String[] r = result.split(System.lineSeparator());
staticString = r[0];
this.i = Integer.parseInt(r[1]);
this.j = Integer.parseInt(r[2]);
}
//implement this method - реализуйте этот метод
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ClassWithStatic that = (ClassWithStatic) o;
if (i != that.i) return false;
return j == that.j;
}
@Override
public int hashCode() {
int result = i;
result = 31 * result + j;
return result;
}
}
}