1
我使用此代码来验证文件的数字符号,构造函数打印文件的上下文,但我想知道如何将打印保存为变量,因为构造函数仅使用“打造”对象,这是代码:从构造函数中获取一个变量
public class VerifyMessage {
private List<byte[]> list;
@SuppressWarnings("unchecked")
// The constructor of VerifyMessage class retrieves the byte arrays from the File and prints the message only if the signature is verified.
public VerifyMessage(String filename, String keyFile) throws Exception {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(filename));
this.list = (List<byte[]>) in.readObject();
in.close();
System.out.println(verifySignature(list.get(0), list.get(1), keyFile) ? "VERIFIED MESSAGE" + "\n----------------\n" + new String(list.get(0)) : "Could not verify the signature.");
}
我怎样才能‘拯救构造的外部’的System.out.println作为全球成员字符串变量? 提前致谢
嗯......你可以一个新的'String'字段添加到类和'VerifyMessage分配给它()'。顺便说一下,Java编码约定声明我们不会为第一个字母命名使用大写字母的方法。 –