有没有办法创建具有标记功能的 FileInputStream?

发布于 10-28 05:40 字数 78 浏览 9 评论 0原文

有没有可能的方法来创建 FileInputStream 并将支持的功能标记为 true

Is there any possible way to create FileInputStream with mark supported feature as true?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

一杆小烟枪2024-11-04 05:40:18

将 Fileinputstream 包装在 BufferedInputStream 中。

缓冲流支持标记。

Wrap your Fileinputstream inside a BufferedInputStream.

The buffered streams support marks.

匿名。2024-11-04 05:40:18

将其包装在 BufferedInputStream

而不是

FileInputStream fis = new FileInputStream(...);

这样做:

BufferedInputStream bis = new BufferedInputStream(new FileInputStream(...));

并使用 bis 而不是 fis;您的代码中不需要更改任何其他内容。

Wrap it in BufferedInputStream.

instead of

FileInputStream fis = new FileInputStream(...);

do this:

BufferedInputStream bis = new BufferedInputStream(new FileInputStream(...));

and use bis instead of fis; nothing else should have to change in your code.

若水微香2024-11-04 05:40:18

BufferedInputStreams 并不神奇。它们仅支持与其底层缓冲区一样大的标记,并且这些缓冲区将占用内存。因此,如果您沿着这条路线走下去,那么了解用例并可能使用适当大小的缓冲区调用 BufferedInputStream 构造函数非常重要。如果底层文件开始变大并且您标记得足够远,那么此技术可能不适合您。

BufferedInputStreams are not magic. They will only support marking for as large as their underlying buffers and these buffers are going to take up memory. So if you go down this route its important that you understand the usage case and potentially call the BufferedInputStream constructor with the appropriatedly sized buffer. If the underlying file starts to get large and you mark far enough back then this technique may not work for you.

丶视觉2024-11-04 05:40:18

尝试这样的事情

public FileInputStream fstream;
public DataInputStream in;
public BufferedInputStream bs;
public String path;

public void myExample() throws IOException{
    path = "yourPath";
    try {
        fstream = new FileInputStream(path);
        in = new DataInputStream(fstream);
        bs = new BufferedInputStream(new InputStreamReader(in));

        //do something

        br.close(); //when do something is completed
        } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, "File not found");
        }
        }

Try something like this

public FileInputStream fstream;
public DataInputStream in;
public BufferedInputStream bs;
public String path;

public void myExample() throws IOException{
    path = "yourPath";
    try {
        fstream = new FileInputStream(path);
        in = new DataInputStream(fstream);
        bs = new BufferedInputStream(new InputStreamReader(in));

        //do something

        br.close(); //when do something is completed
        } catch (FileNotFoundException ex) {
        JOptionPane.showMessageDialog(null, "File not found");
        }
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文