Main
来源:互联网 发布:荣耀v10网络制式 编辑:程序博客网 时间:2024/05/19 20:22
字节流与字符流
package com.io;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import javax.imageio.stream.FileImageInputStream;
public class Main {
public static void main(String[] args) {
// 流 按方向分为 输入流 ,输出流
// 流按数据分为 字节流 ,字符流
//IO分两种流
//字节流 InputStream OutputStream
//字符流 Reader Writer
//具体的实现方法
//字节流 FileInputStream FileOutputStream
//字符流 FileReader FileWriter
// 获得文件
// 输入文件
// File inFile = new File(pathIn);
String pathIn = “/Users/dllo/Desktop/Hello/”;
File inFile = new File(“/Users/dllo/Desktop/input/”);
// 输出文件
File outFile = new File(“/Users/dllo/Desktop/output/”);
// 输入流
try {
// 输入流 对象
FileInputStream fis = new FileInputStream(inFile);
// 输出流 对象
FileOutputStream fos = new FileOutputStream(outFile);
// 创建一个存储输入流数据的byte数组
// byte [] buffer = new byte[1024];
byte[] buffer = new byte[(int) inFile.length()];
// 读流
fis.read(buffer);
// 写流
fos.write(buffer);
// 关流 fis.close(); fos.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } // 字符流 File playFile = new File("/Users/dllo/Desktop/info/"); try { // 字符流对象 FileReader fr = new FileReader(playFile); BufferedReader reader = new BufferedReader(fr); String line = "";// 每一行的数据 // 一行一行加一起的最终数据 String result = new String(); // 读出一行数据 赋值给line,一直读取,直到其为空 while ((line = reader.readLine()) != null) { // 把读出来的数据都加入result里 result += line; } System.out.println(result);// 打印读取的数据 // 关流 reader.close(); fr.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }}
}
- main
- main()
- Main
- main
- main()
- Main
- main
- main
- Main
- main
- main()
- main()
- main
- Main
- main
- main
- main
- Main
- 第三章View的事件体系
- 解决com.android.volley.NoConnection error, java.io.InterruptedIOException
- 第四章、View的工作原理
- js和qt4 evaluteJavascript
- Hibernate Session 事务隔离级别回顾 持久化对象的状态 Session核心方法
- Main
- Tomcat安装的常见问题以及其第一个应用
- 通过接口定义Fragment之间的跳转
- android 关于textview跑马灯的问题解决方案
- 搭建Appium自动化测试平台环境(基于python&android)
- Google网络请求框架Volley源码浅析(二)
- python命令行自动补全
- Problem C: 数组---求数组中的最大值
- 查找未公开的oracle初始化参数