package com.company;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
public class Main {
public static void main(String[] args) throws IOException {
MyClass myObject = new MyClass();
OutputStream outStream = new FileOutputStream("c:/my-object-data.txt");
myObject.write(5);
while (myObject.available() > 0) {
int data = myObject.read(); //read one int from the input stream
outStream.write(data); //write that int to the other stream.
}
outStream.close();
}
}
class MyClass {
private ArrayList<Integer> list;
public void write(int data) {
list.add(data);
}
public int read() {
int first = list.get(0);
list.remove(0);
return first;
}
public int available() {
return list.size();
}
}
please, why this code doesn't compile?
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Carlos Cortázar
18 November 2019, 14:44
Sorry Guadalupe, this is not a task.
Is an example of code included in the lesson 8 of level 3; "Standard Interfaces: InputStream, OutputStream"
0
Guadalupe Gagnon
18 November 2019, 14:34
what task # is this?
0