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] ...
随机推荐
- get方式提交中文乱码解决
get方式提交中文时会乱码,过滤器只过滤post请求,此时可修改tomcat配置文件server.xml,为Connector添加属性URIEncoding="utf-8". ec ...
- 不管你以后写不写JS,都应该学会这种思考方式
昨天在网上看到了一篇文章说程序员写不过35这种说法,但事实上,确实并不能每个人都像我一样,在写JS中找到乐趣,就乐意写这东西直到50岁眼瞎为止. 那肯定有人要问,也许我不仅写JS写不到35,可能我连3 ...
- Spring中的自动装配
src\dayday\Person.java package dayday;/** * Created by I am master on 2016/11/28. */public class Per ...
- 没有为扩展名.htm注册的生成提供程序,没有为扩展名.html注册的生成提供程序
在web.config中添加下面这段 代码如下 <buildProviders> <add extension=".html" type="System ...
- 对于undefined和null,还有处理这一类的数组
var total=0; var data=new Array(5);//定义了data数组,length为5,但是都是元素都是undefined. for(i=0;i<data.length; ...
- Codeforces Round #376 (Div. 2)
A 模拟 #include <cstdio> #include <cstring> int Ans; ]; inline ?x:-x;} inline int Min(int ...
- 题目: 求1+2+...+n,要求不使用乘除发、for、while、if、else、switch、case、等关键字以及条件判断语句(A?B:C)
#include <iostream> using namespace std; int add_(int a,int b){ return 0; } int Add(int i,bool ...
- GitHub菜鸟日志1——20160531
好吧,事实上很早就知道有github这个东西了,然而就有一种莫名的力量一直阻止着我向这“未知的领域”涉足(which is called lazy). 然后,前略...总之,默默的就开始了github ...
- phpMyAdmin上传文件大小限制
今日偶然要导一张数据表至mysql数据库中,但发现文件为2.9M,导入失败. 看一下返回的错误原因为文件超过2M的大小限制,郁闷. 找了一下“越狱”的方法,需要修改php.ini和phpmyadmin ...
- iOS--UIView和UIWindow用法
基础 UI(user interface)是用户界面:iOS的应用是由各种各样的UI控件组成 UIWindow就是一个窗口,学的第一个基础类,就是一个容器,可以在容器上放不同的内容,每个app都需要借 ...