我想读一个如下所示的txt文件(parameters.txt):
1
5
8
wa
wb
这是我的代码来迭代它:
private void storeCacheParams() {
try {
BufferedReader reader = new BufferedReader(new FileReader(parameters));
int cache = reader.read();
if ( cache == 1 ) {
cacheType = "direct-mapped";
} else if ( cache == 2 ){
cacheType = "2-way set associative";
}
offsetBits = reader.read();
indexBits = reader.read();
allPol = reader.readLine();
writePol = reader.readLine();
System.out.println("Cache: " + cacheType);
System.out.println("Offset Bits: " + offsetBits);
System.out.println("Index Bits: " + indexBits);
System.out.println("Allocation Policy: " + allPol);
System.out.println("Write Policy: " + writePol);
} catch (IOException e ) {
e.printStackTrace();
}
}
我将我读取的每一行存储到一个int或String变量中。这是我的变量声明:
private String cacheType;
private int offsetBits;
private int indexBits;
private String allPol;
private String writePol;
问题在于打印出来:
Cache: 2-way set associative
Offset Bits: 13
Index Bits: 10
Allocation Policy: 5
Write Policy: 8
但偏移位应为5,索引位应为8,allPol应为wa,writePol应为wb。我的程序从哪里获得13和10?