是否有任何可能的方式创建FileInputStream
与标记支持的功能为true
?有没有办法用标记功能创建FileInputStream?
回答
将您的Fileinputstream包装在BufferedInputStream之内。
缓冲流支持标记。
将它包装在BufferedInputStream
中。
,而不是
FileInputStream fis = new FileInputStream(...);
做到这一点:
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(...));
,并使用bis
,而不是fis
;在你的代码中没有其他东西需要改变。
俄罗斯文件名是不是在这一行中发现异常新的FileInputStream(...)我应该怎么做其他所有文件工作正常,但俄罗斯字符不支持文件名 – 2014-02-10 12:51:18
很有可能会出现“重置为无效标记”IOException原因。 – ha9u63ar 2017-11-17 11:11:43
尝试这样的事情
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");
}
}
BufferedInputStreams不是魔法。它们只支持与其基础缓冲区一样大的标记,并且这些缓冲区将占用内存。所以,如果你沿着这条路线走下去,那么重要的是你要理解用例,并且可能用适当大小的缓冲区调用BufferedInputStream构造函数。如果底层文件开始变大,并且标记足够远,那么此技术可能无法为您工作。
- 1. 有没有办法让所有活动都可用的功能?
- 2. 有没有办法为WinForms组合框创建“标题行”?
- 3. 有没有办法创建一个不能为null的枚举?
- 4. 有没有办法从C#中调用“Identify Monitors”功能?
- 5. WPF/XAML:有没有办法在功能上使用x:static?
- 6. 有没有办法在iPhone中禁用录音功能?
- 7. 有没有办法使用Wand的ImageMagick的vignette功能?
- 8. 有没有办法禁用标签?
- 9. 有没有办法在XBL中创建私有方法?
- 10. 有没有办法让ON_CALL模拟功能“有趣”?
- 11. 有没有办法让文档与他们记录的功能分开?
- 12. 有没有办法记录httpsession超时?
- 13. 有没有办法记录SQLite查询?
- 14. 有没有什么办法可以用Sourcesafe创建配置项
- 15. IN SSRS,有没有办法来禁用rdl.data文件创建
- 16. 有没有办法用Python创建Eclipse插件?
- 17. 有没有办法使用subversion创建shorcut文件? (windows)
- 18. 有没有什么办法可以用Tag Helper创建循环?
- 19. 有没有办法在gem内创建rails应用程序?
- 20. 有没有办法用CloudFormation/Terraform创建EMR安全配置
- 21. 有没有办法使用Terraform创建Azure Data Science VM?
- 22. 有没有办法用会话令牌创建S3连接?
- 23. 有没有办法删除用ajaxSuccess创建的监听器?
- 24. 有没有办法用HTML 5数据属性创建ActionLink?
- 25. 有没有办法用Cargo创建C库?
- 26. 有没有办法用AngularJS创建自定义动画事件
- 27. 有没有办法禁用'iOS Team Provisioning Profile:*'自动创建?
- 28. 有没有办法用参数创建nunit安装程序
- 29. Emacs:有没有办法使用Emacs创建交互式脚本?
- 30. 有没有办法用mcrypt_cbc函数创建http认证密码?
看看这个答案:http://stackoverflow.com/a/18665678/1366 – Adam 2014-06-03 18:44:51