示例#1
0
  public static boolean copyFile(File inputFile, File outputFile, Boolean moveFile) {

    if (!inputFile.exists()) return false;

    if (outputFile.exists()) outputFile.delete();

    InputStream in;

    try {

      in = new FileInputStream(inputFile);
      OutputStream out = new FileOutputStream(outputFile);

      byte[] buffer = new byte[65536];
      int bytesRead = -1;

      while ((bytesRead = in.read(buffer)) != -1) out.write(buffer, 0, bytesRead);

      in.close();
      out.close();
    } catch (FileNotFoundException e) {
      if (Main.isDebug()) e.printStackTrace();
      return false;
    } catch (IOException e) {
      if (Main.isDebug()) e.printStackTrace();
      return false;
    }

    if (moveFile) inputFile.delete();

    return true;
  }
示例#2
0
  public static String getPlsTitle(File file) {
    String result = file.getName();

    if (!file.exists()) return file.getName();

    try {
      BufferedReader br = new BufferedReader(new FileReader(file));

      String inLine;
      while ((inLine = br.readLine()) != null) {
        if (inLine.toLowerCase().contains("title") && inLine.length() > 7) {
          if (inLine.contains("(#")
              && inLine.contains(" - ")
              && inLine.contains("/")
              && inLine.contains(") ")) {
            String[] split = inLine.split("\\) "); // remove number of listeners information
            if (split != null && split.length > 1) {
              result = split[1];
              break;
            }
          } else {
            result = inLine.substring(7);
            break;
          }
        }
      }
      br.close();

    } catch (FileNotFoundException e) {
      if (Main.isDebug()) e.printStackTrace();
    } catch (IOException e) {
      if (Main.isDebug()) e.printStackTrace();
    }

    return result;
  }