目录
1、字节输出流:FileOutputStream
@Test
public void test() throws Exception {
FileOutputStream fileOutputStream = new FileOutputStream("F:\\111\\1.txt");
String str="lwh";
byte[] bytes = str.getBytes();
fileOutputStream.write(bytes);
fileOutputStream.close();
}
运行结果:
2、 字节输入流:FileIntputStream
@Test
public void test2() throws Exception{
FileInputStream os = new FileInputStream("F:\\111\\1.txt");
byte[] bytes = new byte[3];
int c=0;
while ((c=os.read(bytes))!=-1){
String str = new String(bytes,0,c);
System.out.println(str);
}
运行结果:
3、字节输出流与字节输入流联合使用:
package demo420.demo02;
import org.junit.Test;
import java.io.*;
/**
* @创建人 xiaoliu
* @创建时间 2022/4/20
* @描述
*/
public class Demo01 {
@Test
public void test() throws IOException {
FileInputStream fos = new FileInputStream("C:\\Users\\Administ