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] ...
随机推荐
- EF的增删改查
//获取分组信息 public List<UserGroupLogSys> GetUserGroupLogSyslist(int pageIndex, int pageSiz ...
- red hat enterprise 6安装tftp服务
1--->检查是否安装tftp rpm -qa tftp* 2--->安装tftp yum install -y tftp-server 3--->chkconfig --list| ...
- cocos2dx-3.9 集成admob
Part 1: 安装GoogleMobileAds framework (即admob) 1. 安装Cocoapods,否则解决依赖关系和配置真的会把人不累死也得烦死 sudo gem install ...
- jquery 甘特图开发指南
JQuery.Gantt是一个开源的基于JQuery库的用于实现甘特图效果的可扩展功能的JS组件库. <link rel="stylesheet" href="cs ...
- Direct3D 10学习笔记(二)——计时器
本篇将简单整理Direct3D 10的计时器实现,具体内容参照< Introduction to 3D Game Programming with DirectX 10>(中文版有汤毅翻译 ...
- 佛祖保佑,永无bug
/* _ooOoo_ o8888888o 88" . "88 (| -_- |) O\ = /O ____/`---'\____ .' \\| |// `. / \\||| : | ...
- 解决Tomcat7“At least one JAR was scanned for TLDs yet contained no TLDs”问题
解决Tomcat7“At least one JAR was scanned for TLDs yet contained no TLDs”问题 2013-12-05 21:58:00| 分类: t ...
- Maven学习笔记(1)之安装Maven
此笔记是学习Maven时自己摸索+各种百度而来,并非全部原创,望与各位一同学习,勿拍~勿拍~ 安装步骤 1.下载Maven的最新版本,地址:http://maven.apache.org/downlo ...
- asp.net MVC控制器中返回JSON格式的数据时提示下载
Asp.net mvc在接收的是JSON格式的数据,但是奇怪的是在IE中提示下载文件,其他浏览器中一切正常,下载后,里面的内容就是在控制器中返回的数据.代码如下: 视图中js代码: $("# ...
- 去除手机浏览器input焦点默认边框(直接用outline:none就可以了)
1.使用Chrome的都知道,当鼠标焦点在input.textarea这些元素上时,Chrome默认的会给它们加上黄色的边框,我以前一直以为这是chrome的特性,没法去掉,原来是css的效果,out ...