- 2
- 0
- 约9.1千字
- 约 26页
- 2020-08-01 发布于上海
- 举报
Unit02:? HYPERLINK " \t "_blank 基本IO操作 、? HYPERLINK " \t _blank 文本数据IO操作
package day07;
import java.io.;
import java.io.IOException;
import org.junit.Test;
/**
* java.io.
* 文件字节输出流,是一个低级流。负责将
* 字节数据写入到指定文件中。
* @author Administrator
*
*/
public class FosDemo {
?public static void main(String[] args) throws IOException {
??/*
* 常用构造方法:
* (String path)
?? * ()
? * 上述构造方法创建的FOS是覆盖写操作
? * 即:通过这个流写数据前,会将该文件
? * 中原有内容全部清除,在开始通过这个
? * 流写入内容。
? *
* 还支持重载的构造方法,该构造方法
* 多了一个boolean型参数,该值为true
* 时,则是追加写操作。
* 即:通过该流写出的数据会追加到该
?? * 文件的末尾。
? *
? * 向fos.txt文件中写出数据
? */
?? fos
= new (
?? fos.txt,true
?? );
String str = 摩擦摩擦似魔鬼的步伐;
byte[] data = str.getBytes(UTF-8);
??
fos.write(data);
? System.out.println("写出完毕!");
fos.close();
?
}
?@Test
?public void test() throws IOException{
? fos = new (fos_test.txt",true);// 写出
?String str = "今天是学习JAVA_API的第七天!;
??byte[] data = str.getBytes();
?fos.write(data);
?System.out.println(写出完毕!);
??fos.close();
?}
}
package day07;
import java.io.;
import java.io.IOException;
import org.junit.Test;
/**
* java.io.
* 文件字节输入流,是一个低级流,负责从
* 文件中读取字节数据
* @author Administrator
*
*/
public class FISDemo {
public static void main(String[] args) throws IOException {
? fis
???= new (fos.txt);
?
? byte[] data = new byte[20];
?
int len = fis.read(data);
?
??String str = new String(data,0,len,UTF-8);
?System.out.println(str);
?
?fis.close();
?}
@Test
public void test() throws IOException{
fis = new (fos_test.txt");// 读
byte[] data = new byte[30];
?int len = fis.read(data);
System.out.println(读取完毕!);
? String str = new String(data,0,len);
System.out.println(str);
fis.close();
}
}
package day07;
import java.io.;
import java.io.;
import java.io.IOException;
/**
* 使用文件流实现文件复制
* @author Administrator
*
*/
public class CopyDemo1 {
?public static void main(String[] args) throws IOException {
? fis
? = new (
?? ?"music.mp3"
???); ?
? fos
?? = new (
?? music_cp2.mp3
? );
byte[] dat
原创力文档

文档评论(0)