package lzy; import java.io.*; public class lzy { public static void main(String[] args) throws IOException { File file = new File("lzywort.txt"); String st = "12345abcdef@#%&*软件工程"; if(file.exists()){ //判断该文件是否存在 System.out.println("该文件存在"); } else //该文件不存在,即创建文件 { System.out.println("good good"); try{ file.createNewFile(); System.out.println("该文件已创建"); }catch(Exception e){ e.printStackTrace(); } } try { //输入流 FileWriter fw = new FileWriter(file); fw.write(st); fw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { //输出流 FileReader in = new FileReader(file); char byt[] = new char[1024]; int len = in.read(byt); try { int len1 = in.read(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println(new String(byt,0,len)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
2019.06.12Java上机实验
猜你喜欢
转载自www.cnblogs.com/lizhenyong/p/11008805.html
今日推荐
周排行