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] ...
随机推荐
- Mac上安装与更新Ruby,Rails运行环境
Mac安装后就安装Xcode是个好主意,它将帮你安装好Unix环境需要的开发包,也可以独立安装command_line_tools_for_xcode 1.安装RVM RVM:Ruby Version ...
- sis9280触摸ic 基于rk3288 的安卓4.4的 多点触摸
前言:sis提供的驱动ic.基于rk3288的安卓系统.亲眼看到人家完成一次移植.很激动的记下一些东西..虽然我看不懂.其实现在的工作也不需要看懂.叫人协助就好,只需要知道有这个东西. 1linux下 ...
- iis express 局域网访问
查找到配置文件添加一条绑定局域网可访问的IP地址即可: 事例: <site name="Join.Lims.Mob(11)" id="19"> &l ...
- 从C++转向Java的第一课
序:计算机语言的学习,最快捷的方法是从一种语言映射到另一种语言.Java和C++作为最通用的面相对象高级语言,不论从语法或者编程上都极具相似性和可效仿行,这里的可效仿包括——语法理解可效仿和编程规范可 ...
- 理解python的with语句
Python’s with statement provides a very convenient way of dealing with the situation where you have ...
- 图片压缩工具optipng/jpegoptim安装
[1]还未实践 #yum install optipng -y [2]已成功 #yum install -y libjpeg libjpeg-devel #wget http://freecode.c ...
- WebStorm里面配置运行React Native的方案
以前开发react native项目总是需要打开WebStorm编写代码,Xcode跑项目.显得有点多余. 今天教大家如何直接使用WebStorm这个IDE直接完成编码+运行项目工作.这样就可以不用打 ...
- dom扩展
第十一章 DOM扩展 一.选择符API 1.querySelector()方法 接收一个CSS选择符,返回与该模式匹配的第一个元素,如果没有找到匹配的元素,返回null. 2. ...
- Pyhon环境搭建-window
1.安装python3.4.3版本 地址:(64位)https://www.python.org/ftp/python/3.4.3/python-3.4.3.amd64.msi (32位)http:/ ...
- SAPCAR 压缩解压软件的使用方法
SAPCAR 是 SAP 公司使用的压缩解压软件,从 SAP 网站下载的补丁包和小型软件基本都是扩展名为 car 或 sar 的,它们都可以用 SAPCAR 来解压.下面是它的使用说明: 用法: 创建 ...