예제 #1
0
  // Send File
  public void sendFile(String chunkName) throws IOException {
    OutputStream os = null;
    String currentDir = System.getProperty("user.dir");
    chunkName = currentDir + "/src/srcFile/" + chunkName;
    File myFile = new File(chunkName);

    byte[] arrby = new byte[(int) myFile.length()];

    try {
      FileInputStream fis = new FileInputStream(myFile);
      BufferedInputStream bis = new BufferedInputStream(fis);
      bis.read(arrby, 0, arrby.length);

      os = csocket.getOutputStream();
      System.out.println("Sending File.");
      os.write(arrby, 0, arrby.length);
      os.flush();
      System.out.println("File Sent.");
      //			os.close();
    } catch (FileNotFoundException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      //			os.close();
    }
  }
예제 #2
0
 /**
  * return file content as byte[]
  *
  * @param filename
  * @return
  * @throws IOException
  */
 public static byte[] fileGetBytes(String filename) throws IOException {
   byte[] buffer = new byte[(int) new File(filename).length()];
   BufferedInputStream f = new BufferedInputStream(new FileInputStream(filename));
   f.read(buffer);
   return buffer;
 }