Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.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
Java 查找随机访问文件时发生堆栈溢出错误_Java_File_Overflow_Randomaccessfile - Fatal编程技术网

Java 查找随机访问文件时发生堆栈溢出错误

Java 查找随机访问文件时发生堆栈溢出错误,java,file,overflow,randomaccessfile,Java,File,Overflow,Randomaccessfile,所以我在写一个程序,本质上就是说一个单词是否在提供的词典中。字典是一个randomaccessfile,与字典对应的索引也是一个randomaccessfile。两个文件都相当大 我正在使用递归二进制搜索来检查这个词是否在字典中。当我执行indexFile.lenth()/4以获取索引的最大长度,然后计算中间值并执行indexFile.seek(4*mid)时,我得到一个堆栈溢出错误,我不明白为什么 long mid = (max - min)/2; indexFile.seek(4*mid);

所以我在写一个程序,本质上就是说一个单词是否在提供的词典中。字典是一个randomaccessfile,与字典对应的索引也是一个randomaccessfile。两个文件都相当大

我正在使用递归二进制搜索来检查这个词是否在字典中。当我执行indexFile.lenth()/4以获取索引的最大长度,然后计算中间值并执行indexFile.seek(4*mid)时,我得到一个堆栈溢出错误,我不明白为什么

long mid = (max - min)/2;
indexFile.seek(4*mid);
int wordposition = indexFile.readInt();
int nextword = indexFile.readInt();
int wordlength = (nextword - wordposition)/2;
wordsFile.seek(wordposition);
String finalword = "";
for(int i=0; i<wordlength;i++);
{
    finalword = finalword + wordsFile.readChar();
}

if (word.equals(finalword))
{
    return word;
}
else if (finalword.compareTo(word) > 0)
{
     binarysearch(word, min, (mid - 1));
}
else
{
    binarysearch(word, (mid+1), max); 
    System.out.println("yoooo");
}

if (min > max)
{ return "Word not found";}
long-mid=(max-min)/2;
索引文件查找(4*mid);
int-wordposition=indexFile.readInt();
int nextword=indexFile.readInt();
int-wordlength=(nextword-wordposition)/2;
wordsFile.seek(wordposition);
字符串finalword=“”;
对于(int i=0;i 0)
{
二进制搜索(word,min,(mid-1));
}
其他的
{
二进制搜索(word,(mid+1),最大值);
System.out.println(“yoooo”);
}
如果(最小值>最大值)
{返回“找不到单词”;}

请添加stacktrace。我不太清楚这意味着什么对不起!你能详细说明一下吗。我做了一些打印检查,我认为“字长”部分不起作用,代码的这部分似乎正确吗?试试
long-mid=(max+min)/2相反。@EvanKnowles天哪,我是个白痴哈哈,这绝对是对的。不幸的是,我的字长部分仍然不起作用,出于某种原因,当我在测试每次递归调用后finalword打印出的内容时,它只打印一个字符,知道为什么吗?我们需要看一个文件布局的示例。