【问题标题】:Codename One InputStream and OutputStream代号一 InputStream 和 OutputStream
【发布时间】:2019-09-18 00:57:27
【问题描述】:

我对@9​​87654321@ 和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


    【解决方案1】:

    其实他们应该很不错。理论上,存储允许您使用/ 作为文件名的一部分,但老实说,这不是我们测试过的东西,我不确定这样做是否正确。

    FileSystemStorage 需要绝对路径,因此将始终包含斜杠字符。所以这应该可以正常工作。从技术上讲,FileSystemStorage 路径应该以 file:// 开头,但 API 通常在没有它的情况下工作,以使本机代码集成更容易,因此这不是区分 API 的好方法。

    【讨论】:

      猜你喜欢
      • 2018-02-25
      • 2012-08-03
      • 2014-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-06
      相关资源
      最近更新 更多