import java.io.*;public class FileIO {public static void main(String[] args) {writeText();readText();writeData();readData();}public static void writeText() {try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("./test.txt")))) {bw.write("呀呀呀\n啦啦啦");} catch (Exception ex) {ex.printStackTrace();}}public static void readText() {try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("./test.txt")))) {String line;while ((line = br.readLine()) != null) {System.out.println(line);}} catch (Exception ex) {ex.printStackTrace();}}public static void writeData() {try (DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("test.dat")))) {dos.writeUTF("二进制文件");dos.writeInt(233);} catch (Exception ex) {ex.printStackTrace();}}public static void readData() {try (DataInputStream dis = new DataInputStream(new BufferedInputStream(new FileInputStream("./test.dat")))) {System.out.println(dis.readUTF() + ", " + dis.readInt());} catch (Exception ex) {ex.printStackTrace();}}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。