Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Java by oRLaN ( 15 years ago )
public void sendFile(final File f) {
        Runnable r = new Runnable() {

            public void run() {
                System.out.println("Sending...");
                out.println("@FILE_SEND"); 
                out.println(f.getName()); 
                try {
                    byte[] byteArray = new byte[8192];
                    FileInputStream fis = new FileInputStream(f.getPath());
                    int s;
                    s = (int) f.length() / 8192;
                    if ((f.length() % 8192) != 0) s++;
                    int i;
                    out.println(s); 
                    Main.mainFrame.createProgressPanel(f.getPath(), s);
                    BufferedOutputStream bos = new BufferedOutputStream(clientSocket.getOutputStream(), 4 * 8192);
                    while (s > 0) {
                        i = fis.read(byteArray);
                        bos.write(byteArray, 0, i);
                        bos.flush();
                        Main.mainFrame.progressInStream(1);
                        s--;
                    }
                    fis.close();
                } catch (FileNotFoundException e) {
                    System.err.println("File not found!");
                } catch (IOException e) {
                    System.err.println("IOException");
                }
                System.out.println("Sent");
            }
        };

        new Thread(r).start();
    }

 

Revise this Paste

Children: 33231
Your Name: Code Language: