【发布时间】:2019-09-18 00:57:27
【问题描述】:
我对@987654321@ 和FileSystemStorage 有点困惑。我写了以下方法,但我确信它们没有按预期工作,因为.contains("/")不足以区分我们使用的是Storage还是FileSystemStorage。
你能帮我修复它们吗?谢谢
/**
* Get an InputStream for the given sourceFile, it automatically chooses
* FileSystem API or Storage API
*
* @param sourceFile
* @return
* @throws java.io.IOException
*/
public static InputStream getInputStream(String sourceFile) throws IOException {
if (sourceFile.contains("/")) {
return FileSystemStorage.getInstance().openInputStream(sourceFile);
} else {
// Storage is a flat file system
return Storage.getInstance().createInputStream(sourceFile);
}
}
/**
* Get an OutputStream for the given sourceFile, it automatically chooses
* FileSystem API or Storage API
*
* @param destFile
* @return
* @throws java.io.IOException
*/
public static OutputStream getOutputStream(String destFile) throws IOException {
if (destFile.contains("/")) {
return FileSystemStorage.getInstance().openOutputStream(destFile);
} else {
// Storage is a flat file system
return Storage.getInstance().createOutputStream(destFile);
}
}
【问题讨论】:
标签: codenameone