Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.InetSocketAddress;
- import java.nio.ByteBuffer;
- import java.nio.channels.FileChannel;
- import java.nio.channels.ServerSocketChannel;
- import java.nio.channels.SocketChannel;
- import java.util.List;
- public class Client {
- public static void main(String[] args)
- throws IOException, ClassNotFoundException {
- System.out.println("Receiver Start");
- SocketChannel sChannel = SocketChannel.open();
- if (sChannel.connect(new InetSocketAddress("localhost", 3000))) {
- ObjectInputStream ois =
- new ObjectInputStream(sChannel.socket().getInputStream());
- Song s = (Song)ois.readObject();
- System.out.println("Author is " + s.getAuthor());
- createSong(s);
- }
- System.out.println("End Receiver");
- }
- static void createSong(Song song){
- File file = new File("GTA4.mp3");
- try {
- // Initialize a pointer
- // in file using OutputStream
- OutputStream
- os
- = new FileOutputStream(file);
- // Starts writing the bytes in it
- os.write(song.getArr());
- System.out.println("Successfully"
- + " byte inserted");
- // Close the file
- os.close();
- }
- catch (Exception e) {
- System.out.println("Exception: " + e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement