java oop 第十章 IO
来源:互联网 发布:数据库使用表语句 编辑:程序博客网 时间:2024/06/03 09:20
package cn.happy.IO;import java.io.FileInputStream;public class 字节流 {public static void main(String[] args) throws Exception{// TODO Auto-generated method stubFileInputStream fis=new FileInputStream("E:\\S2226.txt");byte[] bytes=new byte[1024];int date=fis.read(bytes);while(date!=-1){String topString=new String(bytes,0,date);System.out.println(topString);date=fis.read(bytes);}}}
package cn.happy.IO;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;public class 字节流写入 {public static void main(String[] args) throws IOException {FileOutputStream fos=new FileOutputStream("E:\\sss6.txt");String word="hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh";byte[] bytes=word.getBytes();fos.write(bytes);fos.close();}}
------字符流package cn.happy.IO.b;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;public class 字符流读取 {public static void main(String[] args) throws IOException {// TODO Auto-generated method stubFileReader reader=new FileReader("E:\\S2226.txt");char[] chars=new char[1024];int date;while((date=reader.read(chars))!=-1){String top=new String(chars,0,date);System.out.println(top);}reader.close();}}
package cn.happy.IO.b;import java.io.FileWriter;import java.io.IOException;public class 字符流写入 {public static void main(String[] args) throws IOException {FileWriter fWriter=new FileWriter("E:\\S2226.txt");String word="升高的困扰姐咖啡奶粉 的看法那我开三年的 ";fWriter.write(word);fWriter.close();}}
-package cn.happy.IO.c;import java.io.BufferedReader;import java.io.FileNotFoundException;import java.io.FileReader;import java.io.IOException;import java.io.Reader;public class buffer {public static void main(String[] args) throws IOException {Reader reader=new FileReader("E:\\S2226.txt");BufferedReader bf=new BufferedReader(reader);String line;while((line=bf.readLine())!=null){System.out.println(line);}bf.close();reader.close();}}
package cn.happy.IO.c;import java.io.BufferedWriter;import java.io.FileWriter;import java.io.IOException;import java.io.Writer;public class buffereddd {public static void main(String[] args) throws IOException { Writer writer=new FileWriter("E:\\S226.txt"); String ss="wowowowowowwwwwwwwwwwwwwwwwwwwwwwwwww"; BufferedWriter bf=new BufferedWriter(writer); bf.write(ss); bf.close(); writer.close(); }}
----二进制package cn.happy.IO.d;import java.io.DataInput;import java.io.DataInputStream;import java.io.DataOutputStream;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;public class date {public static void main(String[] args) throws IOException {InputStream is=new FileInputStream("E:\\QQ图片20170414115705.jpg"); DataInputStream dis=new DataInputStream(is); OutputStream os=new FileOutputStream("F:\\S2222.jpg"); DataOutputStream dos=new DataOutputStream(os); byte[] bytes=new byte[1024]; int date; while((date=dis.read(bytes))!=-1){ os.write(bytes, 0, date); } dos.close(); os.close(); dis.close(); is.close(); System.out.println("成功");}}
序列化---------------package cn.happy.IO.e;import java.io.Serializable;public class Student implements Serializable{private String name;private int age;public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public Student(String name, int age) {super();this.name = name;this.age = age;}public Student() {super();// TODO Auto-generated constructor stub}}
package cn.happy.IO.e;import java.io.DataOutputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.ObjectOutputStream;import java.io.OutputStream;import java.util.ArrayList;import java.util.List;public class Test {public static void main(String[] args) throws Exception {List<Student> list=new ArrayList<Student>();Student stu=new Student("ddd",1);Student stu1=new Student("eee",2);list.add(stu);list.add(stu1);OutputStream osOutputStream=new FileOutputStream("E:\\S226.txt");ObjectOutputStream dos=new ObjectOutputStream(osOutputStream);dos.writeObject(list);dos.close();osOutputStream.close();System.out.println("成功");}}
0 1
- java oop 第十章 IO
- 第十章 Java IO流编程
- OOP/第十章 File I/O
- 第十章:IO完成端口
- JAVA OOP 第二章继承
- JAVA OOP第三章 多态
- JAVA OOP 第四章 接口
- JAVA OOP第六章 异常
- Java oop 第十一章 CMS
- java oop 第十二章宠物商店
- Day18第十八天 java基础 -------IO流
- Day19第十九天 java基础 -------IO流
- Java基础第十七天--IO流1
- Java基础第十八天--IO流2
- java基础第十七天 io缓冲流
- java OOP
- Java OOP
- JAVA OOP
- 下拉刷新插件
- old: text/html;charset=utf-8, new: text/html; charset=utf-8
- nio实例概述
- 必须记住这几种庄家洗盘的形态
- 时间复杂度的解析
- java oop 第十章 IO
- 服务端返回的数据包含回车符,导致前端报错的解决方法
- LeetCode (3Sum Closest)
- 谁的人生不迷茫 ?! 迷茫的不止是你!
- 使用BigDecimal进行精确运算
- jdbc.properties
- Android Studio 编译报错 Error:Error converting bytecode to dex: Cause: com.android.dex.DexIndexOverflowE
- 保存eclipse个人配置的几种方式
- 关于Express模块的学习