Java Reference
In-Depth Information
{
ioEx.printStackTrace();
}
}while (true);
}
private static void sendFile(String fi leName,
ObjectOutputStream outStream) throws IOException
{
//Step 3…
FileInputStream fi leIn =
new FileInputStream(fi leName);
//Step 4…
long fi leLen = (new File(fi leName)).length();
//Step 5…
int intFileLen = (int)fi leLen;
//Step 5 (cont'd)…
byte[] byteArray = new byte[intFileLen];
//Step 6…
fi leIn.read(byteArray);
//Now that we have fi nished
//with the FileInputStream
fi leIn.close();
//Step 7…
outStream.writeObject(byteArray);
outStream.fl ush();
}
}
Now for the client code…
import java.io.*;
import java.net.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
public class MediaClient
{
private static InetAddress host;
private static fi nal int PORT = 1234;
public static void main(String[] args)
Search WWH ::




Custom Search