我的程序使用大文本文件(45MB)在eclipse中运行和运行良好。导出到 jar 后,访问大型源文件时无法正常工作。小文件(300kB)没有问题
Eclipse:冻结 10 秒,然后准备好加载文件。
罐子:冻结 5 秒,没有任何反应。
我可以对 JAR 进行哪些更改以使其正常运行?
编辑:
public String [] RetreiveTokens(){
String path = Main_Win.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String decodedPath = null;
try {
decodedPath = URLDecoder.decode(path, "UTF-8");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String FileName=decodedPath+"languages/D3.txt";//LangPath+SourceFileLists.get(i);
String content = null;
boolean DictCC = false;
int ContentsAddress=0;
try {
BufferedReader fin;
String lineFromFile="";
try {
fin = new BufferedReader(new FileReader(FileName));
//System.out.println("cc");
lineFromFile = fin.readLine();
lineFromFile=lineFromFile.substring(3);
if(lineFromFile.substring(0,1).equals("#")){
DictCC=true;
for(ContentsAddress=0; fin.readLine().length()>0; ContentsAddress++);
ContentsAddress+=2;
//System.out.println(ContentsAddress);
}
fin.close();
} catch (IOException e) {
e.printStackTrace();
}
//System.out.println(lineFromFile);
//if(!DictCC){
content = new Scanner ( new File (FileName), "UTF-8").useDelimiter("\\Z").next();
//}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] tokens=null;
//String[][] Words_1=new String[2][32];;
if(!DictCC){
content=content.substring(1);
content=content.replace("\r\n\r\n", "\r\n");
tokens = content.split("\r\n");
}
else {
content = content.split("\r\n")[ContentsAddress];
tokens = content.split(" ");
}
for (int t=0; t<tokens.length; t++){
if(tokens[t].contains("\n")){
int index = nthOccurrence(tokens[t], '\n', 0);
tokens[t]=tokens[t].substring(index);
}
if(tokens[t].contains("[")){
tokens[t]=tokens[t].replace(" [", "[");
tokens[t]=tokens[t].replace("] ", "]");
tokens[t]=tokens[t].replaceAll("\\[.*\\]", "");
}
if(tokens[t].contains("<")&&tokens[t].contains(">")){
tokens[t]=tokens[t].replace(" <", "<");
tokens[t]=tokens[t].replace("> ", ">");
tokens[t]=tokens[t].replaceAll("\\<.*\\>", "");
}
tokens[t]=tokens[t].replaceAll("[?¿!¡,.;/'{}]", "");
tokens[t]=tokens[t].replace("\n", "").replace("\r", "");
}
return tokens;
}