Пример #1
0
 private static void makeBackup(File file) {
   if (file == null || !file.isFile()) {
     return;
   }
   String timestamp = new SimpleDateFormat("yyyyMMddHHmm").format(new Date());
   File bakFile = new File(file.getAbsolutePath() + "." + timestamp + ".bak");
   try {
     LFileCopy.copy(file, bakFile);
   } catch (IOException ex) {
     // FIXME
   }
 }
Пример #2
0
  /** dowload a file from the internet */
  public static String downloadFileToString(String urlString) throws IOException {
    URLConnection urlConn;
    InputStream in;

    URL url = new URL(urlString);
    urlConn = url.openConnection();
    // don't wait forever. 10 seconds should be enough.
    urlConn.setConnectTimeout(10000);
    in = urlConn.getInputStream();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
      LFileCopy.copy(in, out);
    } finally {
      try {
        in.close();
      } catch (IOException ex) {
        // munch this
      }
    }
    return new String(out.toByteArray(), "UTF-8");
  }