Tag: 文件输入

从InputStream中删除换行符

我想从java.io.InputStream删除所有换行符(对于\ n和\ r \ n),在读取文件时,相应的方法如下所示: /** * @param target {@linkplain File} * @return {@linkplain InputStream} * @throws Exception */ protected InputStream initInput(final File file) throws Exception { InputStream stream = null; try { if (file.isDirectory()) { // throw exception } if (!file.exists()) { // throw another exception } // // *remove newlines here* // stream […]

在创建FileInputStream对象时使用InputStream而不是FileInputStream有什么不同

这可能是一个愚蠢的,但我想知道背景操作的差异。 InputStream is = new FileInputStream(filepath); FileInputStream is = new FileInputStream(filepath); 上面两行代码之间的区别是什么,以及它们使用的场景。

Java InputStream读取问题

我有一个Java类,我通过InputStream读取数据 byte[] b = null; try { b = new byte[in.available()]; in.read(b); } catch (IOException e) { e.printStackTrace(); } 当我从IDE(Eclipse)运行我的应用程序时,它非常有效。 但是当我导出我的项目并将其打包在JAR中时,read命令不会读取所有数据。 我该怎么办呢? 当InputStream是File(~10kb)时,通常会发生此问题。 谢谢!