//Reading the text file try{ File myFile = new File("C:\Users\Dell\Documents\NetBeansProjects\test.txt").getAbsoluteFile(); FileInputStream in = new FileInputStream(myFile); OutputStream out = connection.getOutputStream();
    int bytes = 0;
    byte[] buffer = new byte[8192];
    int len;
    while ((len = in.read(buffer)) > 0) {
    out.write(buffer, 0, len);
    bytes += len;
}
System.out.println("Transfer completed, " + bytes + " bytes sent");
out.flush();
connection.close();
    }catch(Exception e){
    System.out.println(e.getMessage());
    }
 
    