编译原理 ->实验1
来源:互联网 发布:js横向滚动条插件 编辑:程序博客网 时间:2024/05/22 03:00
import java.io.*;public class IOlianxi1 {public static void main(String[] args) throws IOException {System.out.println("the path: "+System.getProperty("user.dir"));CreateFile("C:/123.txt"); readFile("C:/AbsPath.txt"); writeFile2("C:/RelPath.txt","abcdfdfdfdfddde"); readFile("C:/AbsPath.txt"); copy();}public static boolean CreateFile(String destFileName) throws IOException{File file = new File(destFileName);if(file.exists()){System.out.println("Fail! Here it is!");return false;}file.createNewFile();System.out.println("success!");return true;}public static void readFile(String fileName)throws IOException{File file = new File(fileName);BufferedReader reader = new BufferedReader(new FileReader(file));String br=null;while((br=reader.readLine())!=null){System.out.println(br);}reader.close();}public static void writeFile2(String filePath,String str)throws IOException{PrintWriter pw = new PrintWriter(new FileOutputStream(filePath)); pw.print(str);pw.close();}public void writeFile(String filePath,StringBuffer text)throws IOException{ BufferedWriter rw=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(filePath))); rw.write(new String(text)); rw.close(); } public static void copy_1() throws IOException{FileReader fr=new FileReader("FileReaderDemo2.java");FileWriter fw=new FileWriter("FileReaderDemo2.txt");int ch=0;while((ch=fr.read())!=-1)//循环读取,每次读取一个字符,到达文件尾则返回-1{fw.write(ch);//取从第一个到第num个字符,避免有数据不足3个字符的情况}fw.close();fr.close();}public static void copy() throws IOException{FileReader fr=new FileReader("C:/AbsPath.txt");FileWriter fw=new FileWriter("C:/out.txt");char[] buf=new char[1024];int num=0;while((num=fr.read(buf))!=-1){fw.write(buf,0,num);}fr.close();fw.close();}}
0 0
- 编译原理 ->实验1
- 编译原理->词法分析器的分析
- 编译原理实验1-词法分析
- 编译原理LL(1)文法实验报告
- 编译原理实验源代码
- 编译原理实验
- 编译原理课程实验
- 编译原理实验初步设计
- 编译原理实验一
- 电子科技大学-编译原理实验
- 编译原理实验
- 编译原理实验报告
- 编译原理实验手册
- java程序-编译原理实验
- 编译原理实验----词法分析
- 南工大2010编译原理实验
- 南工大2010编译原理实验
- 南工大2010编译原理实验
- 计划进度
- 7.21 静思过错 默然行动
- 完美解决icloud地图不显示的问题
- 配置终端VIM 文件
- 括号匹配检验
- 编译原理 ->实验1
- 实验1——顺序表例程
- Android数据库操作<一>
- 实验1——顺序表的合并
- 队列
- 数制转换
- 堆栈应用括号匹配实验
- 编译原理:实验二、集合与线性表操作
- Problem B: KMP算法综合应用--余庆