⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example8_9.java

📁 书中的例题
💻 JAVA
字号:
/* 数据流的应用 */
import javax.swing.JOptionPane;
import java.io.*;
import java.util.*;
  class FileRW 
   { 
     int    bytes,f_length;
     byte   buffer[];
     FileInputStream    fileInput;
     FileOutputStream   fileOutput;
     DataInputStream    dataInput;
     DataOutputStream   dataOutput;
    FileRW()
 	 {
	  File file = new File("求佛.wma");
	  f_length=(int)file.length();   //获取文件大小,以便设置数组容量
      buffer = new byte[f_length];
      takeimg();
	  loadimg();
      JOptionPane.showMessageDialog(null,"文件复制并更名成功!\n文件大小为:"+f_length);
      System.exit(0);     //退出程序
     }
     //读取声音文件
    public void takeimg() 
	 {
	  try {
			fileInput = new FileInputStream("求佛.wma");
			dataInput = new DataInputStream(fileInput);
            bytes = dataInput.read(buffer);  
          } catch(IOException ei) { System.out.println(ei); }
     }
     //写入到新文件中
    public void loadimg()
	 {
	  try {
			fileOutput = new FileOutputStream("aa.wma");
			dataOutput = new DataOutputStream(fileOutput);
            dataOutput.write(buffer, 0, bytes) ;
	      } catch(IOException eo) { System.out.println(eo);   }
	  }
  }

 public class Example8_9
  {
    public static void main(String[] args) 
 	 { new FileRW();	}
  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -