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] ...
随机推荐
- TypeScript Handbook 2——接口1(翻译)
接口(Interfaces) One of TypeScript's core principles is that type-checking focuses on the 'shape' that ...
- yum只下载不安装:yumdownloader
如果只想通过yum下载软件的安装包,但是不需要进行安装的话,可以使用 yumdownloader 命令. yumdownloader 命令在软件包 yum-utils 里面. 先安装 yum-util ...
- JavaScript Module Pattern: In-Depth
2010-03-12 JavaScript Module Pattern: In-Depth The module pattern is a common JavaScript coding patt ...
- Java 自定义注解
在spring的应用中,经常使用注解进行开发,这样有利于加快开发的速度. 介绍一下自定义注解: 首先,自定义注解要新建一个@interface,这个是一个注解的接口,在此接口上有这样几个注解: @Do ...
- ios http请求
1.同步请求可以从因特网请求数据,一旦发送同步请求,程序将停止用户交互,直至服务器返回数据完成,才可以进行下一步操作, 2.异步请求不会阻塞主线程,而会建立一个新的线程来操作,用户发出异步请求后,依然 ...
- 初接触BurpLoader工具
初接触burp工具 菜鸟一枚,现在在接触一段时间测试,我在测试功能性的时候,想着网站被黑案例那么多,我是不是也应该弄弄安全性测试了,所以就有了下边的第一次接触BurpLoader工具来测试手机的app ...
- [转]sed命令详解
转载:http://blog.chinaunix.net/u/22677/showart_1076318.html 1.简介 sed是非交互式的编辑器.它不会修改文件,除非使用shell重定向来保 ...
- HDU 1710
http://acm.hdu.edu.cn/showproblem.php?pid=1710 题意:给二叉树的先序遍历和中序遍历,确定后序遍历 解法:复习专业课找的一题,根据先序遍历和中序遍历建树,再 ...
- NGUI 屏幕自适应
雨松MOMO 2014年05月04日 于 雨松MOMO程序研究院 发表 现在用unity做项目 90%都是用NGUI,并且我个人觉得NGUI应该算是比较成熟的UI插件,虽然他也存在很多问题,但是至少 ...
- CentOS 安装 Wine
1. 下载安装包 Wine的中文官网可以下载到最新稳定和开发版本的Wine安装包,根据不同需求可以自行下载 2. 解压安装包,编译前检查 根据不同的平台选择不同的编译选项: For 32-Bit Sy ...