近来在树莓派上搭建了一个aria下载服务器,在配置bt-tracker时发现网上的tracker列表很多都是给客户端用的单行格式文件,有些tracker有五六百行,自己手动操作显然不现实,于是写了个小程序用来自动转换格式。
import java.util.*;
import java.io.*;
public class AriaTracker {
	public static void main(String[] args) {
		Scanner varScanner = new Scanner(System.in);
		System.out.print("input the tracker-list‘s path: ");
		String from = varScanner.nextLine();
		System.out.print("input the list‘s filename:");
		String filename = varScanner.nextLine();
		String temp = convert(from+filename);
                if(temp == null){
                    System.out.println("error! the program will exit!");
                    System.exit(-1);
                }
		try {
			BufferedWriter out = new BufferedWriter(new FileWriter(from+filename+"_aria.txt",true));
			out.write(temp);
			out.close();
		}catch(IOException e) {
			e.printStackTrace();
		}
		System.out.println("Format converted successfully");
	}
	
	private	static String convert(String filepath) {
        try {
            File file = new File(filepath);
            String res="";
            if (file.isFile() && file.exists()) {
                InputStreamReader read = new InputStreamReader(new FileInputStream(file), "UTF-8");
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = bufferedReader.readLine();
                while (lineTxt != null) {
                	if(lineTxt.equals(""))
                	{
                		lineTxt = bufferedReader.readLine();
                		continue;
                	}
                	res=res+lineTxt+",";
                	lineTxt = bufferedReader.readLine();
                }
                return res.substring(0,res.length()-1);
            }
        } catch (UnsupportedEncodingException | FileNotFoundException e) {
            System.out.println("Cannot find the file specified!");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("Error reading file content!");
            e.printStackTrace();
        }
        return null;
    }
}
/home/comixhe/
最后一个分隔符不要忘记输入。
tracker
有后缀要带后缀输入。
原文:https://www.cnblogs.com/comixH/p/12873301.html