我希望将结果保存在文件中并使用递归方法重写对象并且什么都不保存。如果我尝试全局声明 printwriter,那么它会给我错误“默认构造函数无法处理隐式超级构造函数抛出的异常类型 UnsupportedEncodingException。必须定义一个显式构造函数”这是代码
public void lengthFind() {
try {
writer = new PrintWriter("Results.txt", "UTF-8");
fileStreamTest obj = new fileStreamTest();
Scanner s = new Scanner(new File(path));
int max = 0;
while (s.hasNextFloat()) {
int d = (int) s.nextFloat();
// it filters the time stamp
if (d <= 5000) {
String code = obj.GolombCoding(d, dival);
// finding Max length
if (code.length() > max) {
max = code.length();
}
}
}
// Dividend Limit check or increase the Dividend
if (dival == 10) {
writer.println("Divident has reached it Limit !");
i++;
// update the file name
path = "D:/File Compression/Data/low_freq/low_freq/house_1/channel_"
+ i + ".dat";
dival = 10;
} else {
dival = dival + 10;
writer.print("Dividen:" + dival);
}
writer.print("Max Length of File " + i + ": " + max);
writer.println("Path Of the File : " + path);
int counter = 1;
// recall the method
writer.println("Method Call Counter" + counter);
lengthFind();
} catch (IOException e) {
writer.close();
System.out.println("There is no more File");
System.exit(0);
}