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編碼約定聲明我們不會爲第一個字母命名使用大寫字母的方法。 –