Answer the question
In order to leave comments, you need to log in
How can you read certain parts of lines from a file?
There is an adapter class for Writer:
class EntityOutputWriter implements EntityOutput {
private final Writer out;
public EntityOutputWriter(Writer out) {
this.out = out;
}
@Override
public void writePerson(Person person) throws IOException {
int age = person.getAge();
String name = person.getName();
out.write("<person>\n");
out.write(" <age>" + age + "</age>\n");
out.write(" <name>" + name + "</name>\n");
out.write("</person>\n");
out.flush();
}
@Override
public void writePoint(Point point) throws IOException {
out.write("<point x = '" + point.getX() + "' y = '" + point.getY() + "'/>\n");
out.flush();
}
}
<point x = '11' y = '15'/>
<person>
<age>28</age>
<name>Nick</name>
</person>
class EntityInputReader implements EntityInput {
private final Reader src;
public EntityInputReader(Reader src) {
this.src = src;
}
@Override
public Person readPerson() throws IOException {
// some code
// return new Person(???, ???);
}
@Override
public Point readPoint() throws IOException {
// some code
// return new Point(???, ???);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question