package cn.Day1001;
import java.io.FileInputStream;
import java.io.IOException;
public class IO02 {package cn.Day1001;package cn.Day1001;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
public class IO07 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
InputStream is = new FileInputStream("E:/北大青鸟.png");
DataInputStream dis = new DataInputStream(is);
// copy到目标路径。
OutputStream os = new FileOutputStream("F:/北大青鸟1.png");
DataOutputStream dos = new DataOutputStream(os);
byte[] bytes = new byte[1024];
int data;
while ((data = dis.read(bytes)) != -1) {
dos.write(bytes, 0, data);
}
dos.close();
os.close();
dis.close();
is.close();
}
}
import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.io.Reader;public class IO05 {/** * @param args * @throws IOException */public static void main(String[] args) throws IOException {// TODO Auto-generated method stubReader
reader = new FileReader("E:/book.txt");BufferedReader br = new BufferedReader(reader);String line;while ((line = br.readLine()) != null) {System.out.println(line);}br.close();reader.close();}}
package cn.Day1001;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
public class IO06 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
Writer writer = new FileWriter("E:/book.txt");
BufferedWriter bw = new BufferedWriter(writer);
String words = "已经晚了";
bw.write(words);
bw.close();
writer.close();
}
}
/** * @param args * @throws IOException */public static void main(String[] args) throws IOException {// TODO Auto-generated method stubFileInputStream fis = new FileInputStream("E:/book.txt");// 定义一个缓冲区byte[]byte[] bytes = new byte[1024];int data;while ((data
= fis.read(bytes)) != -1) {// 有数据可读String type = new String(bytes, 0, data);System.out.println(type);fis.close();}}}
package cn.Day1001;
import java.io.FileWriter;
import java.io.IOException;
public class IO03 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
FileWriter writer = new FileWriter("E:/book.txt");
String words = "她就像是一道疤!";
writer.write(words);
writer.close();
}
}
package cn.Day1001;
import java.io.FileReader;
import java.io.IOException;
public class IO04 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
FileReader reader = new FileReader("E:/book.txt");
char[] chars = new char[1024];
int data;
while ((data = reader.read(chars)) != -1) {
String temp = new String(chars, 0, data);
System.out.println(temp);
}
reader.close();
}
}
转载请注明原文地址: https://ju.6miu.com/read-674585.html