我继承了一些 J2ME 代码,其中一个类包含以下两种方法:
public DataOutputStream getOutputStream(String filePath) throws IOException
{
return Connector.openDataOutputStream(filePath);
}
public DataOutputStream createOutputStream(String filePath) throws IOException
{
FileConnection fc = (FileConnection)Connector.open(filePath);
if(fc.exists())
return fc.openDataOutputStream();
else
fc.create();
return fc.openDataOutputStream();
}
据我所知,这两种方法的作用完全相同。奇怪的是,这些方法在课堂上是紧挨着的,这意味着无论谁把它们放在那里都知道它们在做什么。
这些方法本质上是一样的吗?我可以摆脱其中之一吗?(或者可能两者兼而有之,考虑一下)。