作业

xiaoxiao2021-02-28  168

/**  * 以字节输入流方式,读取文件中的数据  */ package com.chinasofti.ch19.model4; import java.io.FileInputStream; import java.io.IOException; public class FileInputStreamDemo { public static void main(String[] args) { InputStream(); } public static void InputStream() { FileInputStream fis = null;        try { fis = new FileInputStream("D:\\123\\foDemo.txt"); byte[] b = new byte[1024]; int len = 0; while ( len != -1) { System.out.println(new String(b, 0, len)); len = fis.read(b); } } catch (IOException e) { e.printStackTrace(); } finally { try { fis.close(); } catch (IOException e) { e.printStackTrace(); } } } } 任老师(3497F689A739对话) 18:18:01 /**  * 以字节输出流方式,往文件中写入数据  */ package com.chinasofti.ch19.model4; import java.io.FileOutputStream; import java.io.IOException; public class FileOutputStreamDemo { public static void main(String[] args) { outputStream(); } public static void outputStream() { FileOutputStream fos = null; try { fos = new FileOutputStream("D:\\123\\foDemo.txt"); String str = "你好345"; byte[] b = str.getBytes(); fos.write(b); } catch (IOException e) { e.printStackTrace(); } finally { try { fos.close(); } catch (IOException e) { e.printStackTrace(); } } } } 1) 题目要求:应用FileInputStream类,编写应用程序,从磁盘上读取一个Java程序,并将源程序代码显示在屏幕上  答 2) 题目要求:编写一个Java程序将111,112,113,114,115 这5个数以写入到Dest.txt文件中,并以相反的顺序读出显示在屏幕上
转载请注明原文地址: https://www.6miu.com/read-19229.html

最新回复(0)