Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.Socket;
- public class TaskServeurFichier implements Runnable {
- Socket client;
- public TaskServeurFichier(Socket client) {
- this.client = client;
- }
- public void run() {
- try {
- client.setSoTimeout(20000);
- File f;
- String[] paths;
- f = new File("./");
- paths = f.list();
- BufferedWriter out = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
- BufferedReader inServeur = new BufferedReader(new InputStreamReader(client.getInputStream())) ;
- OutputStream outServeur = client.getOutputStream();
- String fileName = inServeur.readLine();
- System.out.println(fileName);
- FileInputStream file = new FileInputStream(fileName);
- byte buf[] = new byte[512];
- int nbOctets;
- for (String path:paths){
- outServeur.write(("| " + path + "\n").getBytes(), 0, ("| " + path + "\n").length());
- }
- outServeur.write("[END]\n".getBytes(), 0, "[END]\n".length());
- while ((nbOctets = file.read(buf)) != -1) {
- outServeur.write(buf, 0, nbOctets);
- }
- outServeur.close();
- inServeur.close();
- file.close();
- client.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement