文件总体结构
文件输入流
package com.wei;
import java.io.*;
/**
* @Author wei
* @Date 2022/5/11 10:01
* @Version 1.0
*/
public class FileIS {
public static void main(String[] args) throws IOException {
String path = "text.txt";
InputStream fis = new FileInputStream(path);
int temp;
while ( (temp =fis.read() )!= -1){
System.out.print((char)temp);
}
fis.close();//关闭输入流
}
}
文件输出流
package com.wei;
import java.io.*;
/**
* @Author wei
* @Date 2022/5/11 10:01
* @Version 1.0
*/
public class FileOS {
public static void main(String[] args) throws IOException {
String path = "text.txt";
OutputStream fos = new FileOutputStream(path,true);//将文件拼接在后面
fos.write("hello,world!".getBytes("UTF8"));
fos.close();//关闭输出流
}
}
text.txt
hello,world!
通过以上操作可以实现简单的上传下载。