Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.Socket;
- public class Client {
- public static void main(String argv[]){
- try {
- String sentence;
- Socket clientSocket = new Socket("localhost", 2000);
- String fileName = "test.txt";
- OutputStream outServeur = clientSocket.getOutputStream();
- outServeur.write((fileName+"\n").getBytes(), 0, fileName.length()+1);
- InputStream inServeur = clientSocket.getInputStream();
- FileOutputStream fos = new FileOutputStream(fileName);
- int nbOctets;
- byte buffer[] = new byte[1000];
- while ((nbOctets = inServeur.read(buffer)) != -1) {
- String[] parts = new String(buffer).split("[END]", 2);
- System.out.println("Fichiers téléchargeables :");
- System.out.println(parts[0].substring(0,parts[0].length()-1));
- fos.write(parts[1].substring(4).getBytes(), 0, nbOctets);
- }
- fos.flush();
- fos.close();
- outServeur.close();
- inServeur.close();
- clientSocket.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement