не знаю как происходит процесс написания адреса файла-помогите плиз !!
package com.javarush.task.task20.task2001;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/*
Читаем и пишем в файл: Human
*/
public class Solution {
public static void main(String[] args) {
//исправьте outputStream/inputStream в соответствии с путем к вашему реальному файлу
try {
//File your_file_name = File.createTempFile("your_file_name", null);
OutputStream outputStream = new FileOutputStream("D:/in.txt");
InputStream inputStream = new FileInputStream("D:/in.txt");
Human ivanov = new Human("Ivanov", new Asset("home", 999_999.99), new Asset("car", 2999.99));
ivanov.save(outputStream, inputStream);
outputStream.flush();
Human somePerson = new Human();
somePerson.load(inputStream);
inputStream.close();
//check here that ivanov equals to somePerson - проверьте тут, что ivanov и somePerson равны
} catch (IOException e) {
//e.printStackTrace();
System.out.println("Oops, something wrong with my file");
} catch (Exception e) {
//e.printStackTrace();
System.out.println("Oops, something wrong with save/load method");
}
}
public static class Human {
public String name;
public List<Asset> assets = new ArrayList<>();
public Human() {
}
public Human(String name, Asset... assets) {
this.name = name;
if (assets != null) {
this.assets.addAll(Arrays.asList(assets));
}
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Human human = (Human) o;
if (name != null ? !name.equals(human.name) : human.name != null) return false;
return assets != null ? assets.equals(human.assets) : human.assets == null;
}
@Override
public int hashCode() {
int result = name != null ? name.hashCode() : 0;
result = 31 * result + (assets != null ? assets.hashCode() : 0);
return result;
}
public void save(OutputStream outputStream, InputStream inputStream) throws Exception {
PrintWriter writer = new FileWriter(outputStream);
String isName = this.name != null ? "yes" : "no";
String isAsset = this.assets.size() > 0 ? "yes" : "no";
writer.println(isName);
writer.println(isAsset);
if(isName.equals("yes")){//implement this method - реализуйте этот метод
writer.println(this.name);
}
if(isAsset.equals("yes")) {
for(Asset a : assets) {
writer.println(a.getName());
writer.println(a.getPrice());
}
}
writer.flush();
writer.close();
public void load(InputStream inputStream) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
String isNamePresent = reader.readLine();
String isAssetPresent = reader.readLine();
if(isNamePresent.equals("yes")){
this.name = reader.readLine();//implement this method - реализуйте этот метод
}
if(isAssetPresent.equals("yes")){
Asset asset = new Asset(reader.readLine(), Double.parseDouble(reader.readLine()));
this.assets.add(asset);
}
reader.close();
}
}
}