小编Zek*_*jin的帖子

获取Objective-C中指定路径的特定扩展名的文件列表

我对Objective-C很新.我正在开发一个Cocoa应用程序.目前我正在寻找Objective C中这个C#代码的等价物:

string[] fileList = Directory.GetFiles(DownloadPath, "*.jpg");
Run Code Online (Sandbox Code Playgroud)

返回的字符串不一定是完整路径,因为我需要的只是文件名.我已经尝试过NSFileManager但到目前为止还没有好的.谢谢.

编辑:我尝试过使用NSFileManager:

[someFileManager contentsOfDirectoryAtPath:path error:nil];
Run Code Online (Sandbox Code Playgroud)

我也想问:'path'的格式是什么?这听起来很简单,但我对MAC OS文件系统完全无能为力.我使用的路径来自[NSOpenPanel URL],它们看起来像这样:

file://localhost/Users/alex/Movies/
Run Code Online (Sandbox Code Playgroud)

有时我会得到结果,但有些时候返回的NSArray只是空的.我对此非常困惑,所以任何帮助都会受到赞赏.

EDIT2:答案在这里:NSPredicate以多个文件结尾,可能是更好的选择.不过,谢谢你的回答.

cocoa objective-c

24
推荐指数
1
解决办法
2万
查看次数

用BufferedInputStream包装后对原始InputStream的影响

假设我有一个接受InputStream的方法.

此方法需要使用BufferedInputStream包装此InputStream以使用其标记和重置功能.但是,传入的InputStream可能仍然由方法的调用者使用.

public static void foo(InputStream is) throws Exception {
    BufferedInputStream bis = new BufferedInputStream(is);
    int b = bis.read();
}

public static void main(String[] args) {


    try {
        InputStream is = new FileInputStream(someFile);
        foo(is);
        int b = is.read(); // return -1
    }catch (Exception e) {
        e.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是:当读取(或初始化)BufferedInputStream时,原始InputStream究竟发生了什么?

我的假设是,如果读取BufferedInputStream,原始InputStream也将向前移动.但是,在调试我的代码之后,我发现InputStream在读取时会返回-1.

如果在这样的过程之后原始的InputStream不可读,我应该如何实现我的目的:

InputStream is;
foo(is);               // Method only take in generic InputStream object
                       // Processing of the passed in InputStream object require mark and reset functionality
int b = is.read();     // …
Run Code Online (Sandbox Code Playgroud)

java inputstream bufferedinputstream

5
推荐指数
1
解决办法
802
查看次数