我試圖將字符串字節存儲到文本文件中,它在我的電腦中完美工作,但是當我嘗試將其實施到我的Android項目中時,它將其存儲但是當我想要返回字符串字節並將其轉換爲原始字節時,它不起作用。再次它在我的電腦上工作,我不知道爲什麼它不適用於我的Android項目。Android,當讀取存儲的字符串字節數組時,它返回不同的字節數組值
CODE:
try {
String y = "Yyyyyyy";
try {
File file1 = new File(Environment.getExternalStorageDirectory() + File.separator + "test/test/newFile.txt");
if (!file1.createNewFile()) {
EncryptedObject a = encryptedMessage.encrypt(y, "test", "test");
Log.e("BYTES FROM TEXT1", Arrays.toString(a.getEncryptedBytes()));
String example = new String(a.getEncryptedBytes());
Log.e("STRINGGGGG", example);
BufferedWriter buffer = new BufferedWriter(new FileWriter(file1));
buffer.write(example);
buffer.flush();
buffer.close();
BufferedReader readFile = new BufferedReader(new FileReader(file1));
String get_text = "";
String lines = null;
while ((lines = readFile.readLine()) != null) {
get_text += lines; // Gets each line
}
readFile.close();
//THE PROBLEM SEEMS TO START HERE
byte[] dec = get_text.getBytes(Charset.forName("UTF-8"));
Log.e("TEXT", get_text);
Log.e("BYTES FROM TEXT", Arrays.toString(dec));
} else {
System.out.println("File Already Exist");
}
} catch (Exception e) {
e.getCause();
}
}catch (Exception e){
e.printStackTrace();
}
日誌:
04-24 16:41:42.208 2934-2934/com.test.test E/ENCRYPTED TEXT﹕ ϩ{���
04-24 16:41:42.218 2934-2934/com.test.test E/ENCRYPTED TEXT﹕ [-49, -87, 123, -15, 1, -84, -11]
04-24 16:41:42.218 2934-2934/com.test.test E/BYTES FROM TEXT1﹕ [-49, -87, 123, -15, 1, -84, -11]
04-24 16:41:42.218 2934-2934/com.test.test E/STRINGGGGG﹕ ϩ{���
04-24 16:41:42.218 2934-2934/com.test.test E/TEXT﹕ ϩ{���
04-24 16:41:42.218 2934-2934/com.test.test E/BYTES FROM TEXT﹕ [-49, -87, 123, -17, -65, -67, 1, -17, -65, -67, -17, -65, -67]
爲什麼返回不同的字節值?我感謝任何幫助,謝謝。 EDITED。
它適用於正常的字符串,但是當我嘗試加密的郵件它不起作用,但它在我的電腦上工作 – kobbycoder