Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import java.io.*;
  2. import java.net.InetSocketAddress;
  3. import java.nio.ByteBuffer;
  4. import java.nio.channels.FileChannel;
  5. import java.nio.channels.ServerSocketChannel;
  6. import java.nio.channels.SocketChannel;
  7. import java.util.List;
  8.  
  9.  
  10. public class Client {
  11.  
  12. public static void main(String[] args)
  13. throws IOException, ClassNotFoundException {
  14. System.out.println("Receiver Start");
  15.  
  16. SocketChannel sChannel = SocketChannel.open();
  17. if (sChannel.connect(new InetSocketAddress("localhost", 3000))) {
  18.  
  19. ObjectInputStream ois =
  20. new ObjectInputStream(sChannel.socket().getInputStream());
  21.  
  22. Song s = (Song)ois.readObject();
  23.  
  24.  
  25. System.out.println("Author is " + s.getAuthor());
  26. createSong(s);
  27. }
  28.  
  29. System.out.println("End Receiver");
  30. }
  31.  
  32. static void createSong(Song song){
  33. File file = new File("GTA4.mp3");
  34. try {
  35.  
  36. // Initialize a pointer
  37. // in file using OutputStream
  38. OutputStream
  39. os
  40. = new FileOutputStream(file);
  41.  
  42. // Starts writing the bytes in it
  43. os.write(song.getArr());
  44. System.out.println("Successfully"
  45. + " byte inserted");
  46.  
  47. // Close the file
  48. os.close();
  49. }
  50.  
  51. catch (Exception e) {
  52. System.out.println("Exception: " + e);
  53. }
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement