I am trying to write an FTP
client program and I have input and output streams to transfer files between server and my computer.
When I was thinking about how to design the class, I couldn't decide on whether to open up a new InputStream
every time I call the function and then immediately close it (as in the example below).
Or just do this in the constructor and close it while quitting the program. Does it matter? Does it make sense to do it this way, especially if the user has the option to decide to upload another file to the server immediately after doing it once?
public class FTPClientP extends FTP{
private InputStream is;
public FTPC(String serverAdd, int connection_port){
is = null;
}
public int connectToServer() throws IOException{
}
public boolean uploadToServer(File file) throws IOException{
boolean uploaded = false;
is = new FileInputStream(file);
String fileName = myFile.getName();
uploaded = ftp.storeFile(fileName, is);
is.close();
return uploaded;
}
}