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

我在想一些像

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

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

你好像倒退了。

根据定义, 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); 

要从Path打开InputStream ,请使用:

 try ( final InputStream in = Files.newInputStream(path); ) { // work with "in" }