public static void ReadBinaryFile()
{ System.out.println("请输入你要读的文件路径:"); Scanner in = new Scanner(System.in); String path = in.next(); try { FileInputStream inputFile = new FileInputStream(path); DataInputStream input = new DataInputStream(inputFile); FileOutputStream outFile = new FileOutputStream("d:\\first.class"); DataOutputStream output = new DataOutputStream(outFile); int size = input.available(); byte[] me = new byte[size]; input.read(me); output.write(me); output.close(); outFile.close(); input.close(); inputFile.close(); System.out.println("文件复制成功"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void BufferWriter() { // 使用缓冲区存数据 此种效率高 System.out.println("请输入你要写入的文件路径:"); Scanner in = new Scanner(System.in); String path = in.next(); try { FileWriter fw = new FileWriter(path); BufferedWriter bw = new BufferedWriter(fw); System.out.println("请输入你要写进文件的内容"); //bw.write(in.next()); //bw.newLine(); bw.append(in.next());//添加数据 bw.close(); fw.close(); System.out.println("文件写入成功"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void BufferRead() { //使用缓冲区存数据 此种效率高 System.out.println("请输入你要读的文件路径:"); Scanner in = new Scanner(System.in); String path = in.next(); try { FileReader fr = new FileReader(path); BufferedReader br = new BufferedReader(fr); String str = null; while((str=br.readLine())!=null) { System.out.println(str); } br.close(); fr.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }; } public void WriteFile() { System.out.println("请输入你要写入的文件路径:"); Scanner in = new Scanner(System.in); String path = in.next(); try { //写入流 OutputStream file = new FileOutputStream(path); System.out.println("请输入要写入地文件内容:"); String str = in.next(); byte[] words = str.getBytes(); file.write(words); file.close(); System.out.println("写入成功"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void ReadFile() { System.out.println("请输入你要读取的文件路径:"); Scanner in = new Scanner(System.in); String path = in.next(); try { // 读入流 InputStream file = new FileInputStream(path); int size; size = file.available(); System.out.println("文件可读取的最大数:"+size); byte[] text = new byte[size]; file.read(text,0,size); String s = new String(text); System.out.println(s); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }