Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android解析特殊格式txt文件_Android_Algorithm_Parsing_Readfile_Country - Fatal编程技术网

android解析特殊格式txt文件

android解析特殊格式txt文件,android,algorithm,parsing,readfile,country,Android,Algorithm,Parsing,Readfile,Country,我需要一个帮助来解析Android中的特殊格式文件 文件内容粘贴如下 ??en 阿尔巴尼亚 DZ|阿尔及利亚 AD |安道尔 AO |安哥拉 奥乌本戈|本戈 奥乌本格拉|本格拉 奥比|比 奥卡宾达|卡宾达 奥坎多·库班戈|坎多·库班戈 北奥昆萨|北奥昆萨 南澳大利亚南澳大利亚南澳大利亚南澳大利亚 奥库涅|库涅 奥万博|万博 奥乌惠拉|惠拉 奥乌罗安达罗安达 嗯 文件内容以“?”字符开头,我需要以一种更高的方式解析国家代码和城市代码。文档非常混乱。。。也许您可以不使用解析器,而是使用如下内容:

我需要一个帮助来解析Android中的特殊格式文件

文件内容粘贴如下

??en
阿尔巴尼亚
DZ|阿尔及利亚
AD |安道尔 AO |安哥拉
奥乌本戈|本戈
奥乌本格拉|本格拉
奥比|比
奥卡宾达|卡宾达
奥坎多·库班戈|坎多·库班戈
北奥昆萨|北奥昆萨
南澳大利亚南澳大利亚南澳大利亚南澳大利亚
奥库涅|库涅
奥万博|万博
奥乌惠拉|惠拉 奥乌罗安达罗安达


文件内容以“?”字符开头,我需要以一种更高的方式解析国家代码和城市代码。

文档非常混乱。。。也许您可以不使用解析器,而是使用如下内容:

    ArrayList<String> countries = new ArrayList<String>();
    ArrayList<String> sities = new ArrayList<String>();
    ArrayList<String> codes= new ArrayList<String>();
        try {
            BufferedReader br = new BufferedReader(new FileReader(filepath));
            String line = "";
            while ((line = br.readLine()) != null) {
                if(!line.contains("?")){
                String[] data = line.split(("\\|"); // this part maybe you should modify by yourself
                    codes.add(data[0]);
                    countries.add(data[0]);
                    cities.add(data[0]);
                }
            }
            br.close();
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        }
ArrayList countries=new ArrayList();
ArrayList sities=新的ArrayList();
ArrayList代码=新的ArrayList();
试一试{
BufferedReader br=新的BufferedReader(新文件读取器(文件路径));
字符串行=”;
而((line=br.readLine())!=null){
如果(!line.contains(“?”){
String[]data=line.split((“\\\\”);//这部分您可能需要自己修改
代码。添加(数据[0]);
添加(数据[0]);
城市。添加(数据[0]);
}
}
br.close();
}捕获(FileNotFoundException e1){
e1.printStackTrace();
}

希望它会有用。

可能我的问题不清楚。但是你的回答对我的问题很有帮助。谢谢。