有没有办法确定输入流是否是readOnly?

Way*_*les -2 java inputstream

我在想类似的东西

File file =new File(inputStream) // not possible though. file.canWrite,

但我似乎找不到一个解决方案,将输入流转换为文件,而无需将其写入别处.谢谢!

fge*_*fge 5

你似乎倒退了.

根据定义,InputStream只有字节流来自哪里才会允许您读取字节流.它可能来自文件,网络套接字或自定义提供程序.按照它的定义,你只能从中读取InputStream.

由于您似乎在此处使用文件,因此您可以使用以下命令检查文件是否只为运行当前进程的用户读取:

final Path path = Paths.get("path/to/my/file");

// is it writable? If no, consider "read only"
final boolean canWrite = Files.isWritable(path);
Run Code Online (Sandbox Code Playgroud)

并打开InputStream一个Path,使用:

try (
    final InputStream in = Files.newInputStream(path);
) {
    // work with "in"
}
Run Code Online (Sandbox Code Playgroud)