title: Send MP3 and JPEG file over socket properly over Socket in java
body: <p>SERVER (receive file)          </p>
  
  <pre><code>     String ip=JOptionPane.showInputDialog(this,"Enter Port Number :");
        String folder=jTextField2.getText();
        try
        {
         ServerSocket sskt= new ServerSocket(Integer.parseInt(ip));
  Socket skt= sskt.accept();
  InputStream is= skt.getInputStream();
  
  
  
  byte[] bytes= new byte[1024*16];
  
  DataInputStream dis=new DataInputStream(skt.getInputStream());
          String ext=dis.readUTF();
  
    System.out.println("extension read");
  
  
  
   String path=folder+"/file."+ext;
  JOptionPane.showMessageDialog(this, path);
  File f= new File(path);
  OutputStream output = new FileOutputStream(f);
  while(is.read(bytes)&gt;0)
  {
    output.write(bytes);
   System.out.println("byte read");
  }
  System.out.println("Done!!!");
  
  }
   catch(Exception e)
   {
   System.out.println(e);
     }
  </code></pre>
  
  <p>CLIENT(send File)</p>
  
  <pre><code>      String ip=JOptionPane.showInputDialog(this,"enter server ip:");
          String port=JOptionPane.showInputDialog(this,"enter port number :");
           File file=new File(jTextField1.getText());
          String name=file.getName();
         String n=  name.substring(name.lastIndexOf(".") + 1);
  
  
  
          try {
              Socket skt=new Socket(ip, Integer.parseInt(port));
              OutputStream os=  skt.getOutputStream();
              DataOutputStream dos= new DataOutputStream(os);
              dos.writeUTF(n);
              os.flush();
  
  
              FileInputStream fis= new FileInputStream(file);
              BufferedInputStream bis= new BufferedInputStream(fis);
              byte[] mybytearray = new byte[(int) file.length()];
              bis.read(mybytearray, 0, mybytearray.length);
              os.write(mybytearray, 0, mybytearray.length);
              JOptionPane.showMessageDialog(this,"Done!!");
              os.close();
          }
  
          catch (Exception ex) {
              System.out.println(ex);
          }
  </code></pre>
  
  <p>i am able to transfer all formats of file bt mp3 and jpeg files do not open properly. Media player is not able to play any mp3 file bt size of file created at server is same as that send by client</p>
  
  <p>anyone can please help me out with this</p>