java只能进行TCP/IP上的传输,看看JDK文档中的java.net包(java.net.Socket,java.net.ServerSocket等)

解决方案 »

  1.   

    我大体查了一下JAVA的API,它有专门的Sound类,可以对指定的声音文件进行读取操作:static AudioInputStream getAudioInputStream (java.io.File file) 
    static AudioInputStream getAudioInputStream (java.net.URL url) 
    static AudioInputStream getAudioInputStream (java.io.InputStream stream)读取声音文件大概需要三步:
    reading that file's audio data involves three steps: 1、Get an AudioInputStream object from the file. 
    2、Create a byte array in which you'll store successive chunks of data from the file. 
    3、Repeatedly read bytes from the audio input stream into the array. On each iteration, do something useful with the bytes in the array (for example, you might play them, filter them, analyze them, display them, or write them to another file)。The following code example outlines these steps. int totalFramesRead = 0;
    File fileIn = new File(somePathName);
    // somePathName is a pre-existing string whose value was
    // based on a user selection.
    try {
      AudioInputStream audioInputStream = 
        AudioSystem.getAudioInputStream(fileIn);
      int bytesPerFrame = 
        audioInputStream.getFormat().getFrameSize();
      // Set an arbitrary buffer size of 1024 frames.
      int numBytes = 1024 * bytesPerFrame; 
      byte[] audioBytes = new byte[numBytes];
      try {
        int numBytesRead = 0;
        int numFramesRead = 0;
        // Try to read numBytes bytes from the file.
        while ((numBytesRead = 
          audioInputStream.read(audioBytes)) != -1) {
          // Calculate the number of frames actually read.
          numFramesRead = numBytesRead / bytesPerFrame;
          totalFramesRead += numFramesRead;
          // Here, do something useful with the audio data that's 
          // now in the audioBytes array...
        }
      } catch (Exception ex) { 
        // Handle the error...
      }
    } catch (Exception e) {
      // Handle the error...
    }以上摘自java api(Java Sound Programmer Guide)