IO:InputStream
InputStream类(java.io.InputStream)
public abstract class InputStream extends Object implements Closeable
构造方法:public InputStream()
普通方法:
|
public abstract int read()throws IOException |
依次读取单个字节数据,如果没有内容则返回-1 |
|
public int read(byte[] b) throws IOException |
读出输入流的数据,写入字节数组,返回实际读取到的长度,如果没有内容则返回-1 |
|
public int read(byte[] b, int off, int len) throws IOException |
读出输入流指定长度的数据,写入字节数组的指定位置,返回实际读取到的长度,如果没有内容则返回-1。但是当指定长度为0时返回0; |
|
public void close()throws IOException |
关闭数据流 |
FileInputStream(java.io.FileInputStream)
public class FileInputStream extends InputStream
构造方法:
|
public FileInputStream(File file) throws FileNotFoundException |
从文件创建输入流(File类) |
|
public FileInputStream(String name) throws FileNotFoundException |
从文件创建输入流(String类) |
实例:
|
test1.txt的内容 |
0123456789abcdefghijklmn |
|
Test2.txt的内容 |
01234 |
|
package wiki.jjcc.test.ips;
import java.io.File; import java.io.FileInputStream; import java.io.InputStream;
public public String s = File.separator; File file1 = new File("d:"+s+"temp"+s+"test1.txt"); File file2 = new File("d:"+s+"temp"+s+"test2.txt"); InputStream input = new FileInputStream(file1); byte[] b1 = new byte[] b2 = new int int System.out.println(num1); System.out.println("["+new String(b1)+"]"); System.out.println(num2); System.out.println("["+new String(b2)+"]"); input.close(); } } |

|
package wiki.jjcc.test.ips;
import java.io.File; import java.io.FileInputStream; import java.io.InputStream;
public public String s = File.separator; File file1 = new File("d:"+s+"temp"+s+"test1.txt"); File file2 = new File("d:"+s+"temp"+s+"test2.txt"); InputStream input = new FileInputStream(file2); byte[] b1 = new byte[] b2 = new int int System.out.println(num1); System.out.println("["+new String(b1)+"]"); System.out.println(num2); System.out.println("["+new String(b2)+"]"); input.close(); } } |

|
package wiki.jjcc.test.ips;
import java.io.File; import java.io.FileInputStream; import java.io.InputStream;
public public String s = File.separator; File file = new File("d:"+s+"temp"+s+"test1.txt"); InputStream input = new FileInputStream(file); byte[] b = new int int while((temp=input.read())!=-1){ b[foot++]=(byte)temp; } System.out.println(temp); System.out.println("["+new String(b)+"]"); input.close(); } } |

IO:InputStream的更多相关文章
- struts2文件下载 出现Can not find a java.io.InputStream with the name的错误
成功代码: 前台界面jsp: <a style="text-decoration:none;" href="<%=path %>/main/frontN ...
- 关于Mysql数据库longblob格式数据的插入com.mysql.jdbc.PreparedStatement.setBinaryStream(ILjava/io/InputStream;J)V问题分析
当数据库字段为blob类型时 ,我们如果使用PreparedStatement中的setBinaryStream(int,InputStream,int)方法需要注意 在向blob字段类型中插入数据时 ...
- struts2文件下载出现Can not find a java.io.InputStream with the name的错误
今天在用struts2就行文件下载时出现如下错误: Servlet.service() for servlet default threw exception java.lang.IllegalArg ...
- 【java】io流之字节输入流:java.io.InputStream类及子类java.io.FileInputStream
package 文件操作; import java.io.File; import java.io.FileInputStream; import java.io.IOException; impor ...
- Error: Default interface methods are only supported starting with Android N (--min-api 24): java.io.InputStream org.apache.poi.sl.usermodel.ObjectShape.readObjectData()
项目运行的时候,如果报错 Error: Default interface methods are only supported starting with Android N (--min-api ...
- java.lang.NoSuchMethodError: org.springframework.util.StreamUtils.emptyInput()Ljava/io/InputStream;
今天写用spring的MockMvc测试controller的demo时出现了这个错误,条件反射的进行了百度,没有搜到匹配的答案,但给了一些解决问题的思路:首先NoSuchMethodError要不就 ...
- ava.io.InputStream & java.io.FileInputStream
java.io.InputStream & java.io.FileInputStream java.io.InputStream,这个抽象类是表示字节输入流的超类,这个抽象类的共性的方法有: ...
- Can not find a java.io.InputStream with the name [downloadFile] in the invocation stack.
1.错误描写叙述 八月 14, 2015 4:22:45 下午 com.opensymphony.xwork2.util.logging.jdk.JdkLogger error 严重: Excepti ...
- java io InputStream 转 byte
InputStream is ; ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] b = new byte[1024] ...
随机推荐
- HTML DOM
1.DOM方法 常用 getElementById() 返回带有指定 ID 的元素 getElementsByTagName() 返回包含带有指定标签名称的所有元素的节点列表(集合/节点数组) ge ...
- Oracle中INSTR、SUBSTR和NVL的用法
Oracle中INSTR.SUBSTR和NVL的用法 INSTR用法:INSTR(源字符串, 要查找的字符串, 从第几个字符开始, 要找到第几个匹配的序号) 返回找到的位置,如果找不到则返回0. 默认 ...
- Hadoop原理介绍
Hadoop核心之HDFS 架构设计 老嗨 2015-09-18 16:55:00 浏览225 评论0 摘要: 概述:HDFS即Hadoop Distributed File System分布式文 ...
- Hadoop入门系列一
作者:Aitian Ma链接:https://www.zhihu.com/question/24965053/answer/102858134来源:知乎著作权归作者所有,转载请联系作者获得授权. Ha ...
- 关于docker容器是怎样建立新的namespace的。
最近博客收到了一封交流的私信,感谢您的关注:现在就我理解的docker建立容器时namespace的建立问题做一个 个人的回答: 一,从原理角度来讲: docker创建container,说白了就是l ...
- article和section
article和section都是指页面中的块,但是article更加强调独立性,而section常被用来分块. section使用禁忌: 1.不要把section当作定义样式的容器,因为那是div的 ...
- 全国大学列表文件(较新)+ nodejs导入mongodb数据库
直接上代码 'use strict' var fs=require('fs'), mongodb=require('mongodb').MongoClient, assert=require('ass ...
- [搬砖]Pycharm中启动IPython notebook失败提示load_entry_point ImportError: Entry point ('console_scripts', 'ipython') not found的解决方法
前提:直接运行ipython正常,“which -a ipython”命令显示也只有一个ipython存在,在ipynb文件中点运行启动notebook时提示错误类似如下: Traceback (mo ...
- 函数中的static静态变量
静态变量仅在局部函数域中存在且只被初始化一次,当程序执行离开此作用域时,其值不会消失,会使用上次执行的结果. <?php function testStatic($start,$end){ st ...
- Watin 杂谈
Web自动化测试(三)[弹出窗口处理] http://blog.csdn.net/cctv_hu/article/details/5984373 http://www.cyqdata.com/cnbl ...