我在写字板(文本后的新行)中得到了完美的结果,但我无法使用下面的代码在记事本中获得新行。并希望获得与我在 word pad 中获得的相同结果。
private void getIntentDetails() {
intent = getIntent();
if (intent.hasExtra("testName")) {
testName = (String) intent.getExtras().get("testName");
Log.e("testName ", "testName " + testName);
appendLog("TestName : ");
appendLog(testName);
appendLog(", ");
//appendLog("\n");
}
if (intent.hasExtra("testDate")) {
testDate = (String) intent.getExtras().get("testDate");
Log.e("testDate ", "testDate " + testDate);
appendLog("TestDate : ");
appendLog(testDate);
appendLog(", ");
}
if (intent.hasExtra("testTime")) {
testTime = (String) intent.getExtras().get("testTime");
Log.e("testTime ", "testTime " + testTime);
appendLog("TestTime : ");
appendLog(testTime);
appendLog(", ");
}
if (intent.hasExtra("savedName")) {
savedName = (String) intent.getExtras().get("savedName");
Log.e("savedName ", "savedName " + savedName);
appendLog("SavedName : ");
appendLog(savedName);
appendLog(", ");
}
if (intent.hasExtra("sensitivity")) {
sensitivity = (String) intent.getExtras().get("sensitivity");
Log.e("sensitivity ", "sensitivity " + sensitivity);
appendLog("Accelerometer Sensitivity : ");
appendLog(sensitivity);
appendLog(" , ");
}
if (intent.hasExtra("xvalues")) {
xValues = (ArrayList<Float>) intent.getExtras().get("xvalues");
Log.e("xValues ", "xValues " + xValues.size());
for (int indexx = 0; indexx < xValues.size(); indexx++) {
xvalue = xValues.get(indexx).toString();
if (indexx == 0) {
appendLog("X-Values : ");
}
appendLog(xvalue);
appendLog(", ");
}
}
Log.d("X-Values : ", ""+ xValues.size());
if (intent.hasExtra("yvalues")) {
yValues = (ArrayList<Float>) intent.getExtras().get("yvalues");
Log.e("yValues ", "yValues " + yValues.size());
for (int indexy = 0; indexy < yValues.size(); indexy++) {
yvalue = yValues.get(indexy).toString();
if (indexy == 0) {
appendLog("Z-Values : ");
}
appendLog(yvalue);
appendLog(", ");
}
}
Log.e("Z-Values : ", ""+ yValues.size());
if(intent.hasExtra("xpos")){
xPos = (String[]) intent.getExtras().get("xpos");
}
// for(int m = 0; m< xPos.length;m++){
// Log.d("xPos", " "+ xPos[m]);
// }
if(intent.hasExtra("xneg")){
xNeg = (String[]) intent.getExtras().get("xneg");
Log.e("xNeg ", "xNeg " + xNeg.length);
}
// for(int m = 0; m< xNeg.length;m++){
// Log.d("xNeg", " "+ xNeg[m]);
// }
if(intent.hasExtra("ypos")){
yPos = (String[]) intent.getExtras().get("ypos");
Log.e("yPos ", "yPos " + yPos.length);
}
// for(int m = 0; m< yPos.length;m++){
// Log.d("yPos", " "+ yPos[m]);
// }
if(intent.hasExtra("yneg")){
yNeg = (String[]) intent.getExtras().get("yneg");
Log.e("yNeg ", "yNeg " + yNeg.length);
}
// for(int m = 0; m< yNeg.length;m++){
// Log.d("yNeg", " "+ yNeg[m]);
// }
}
private void appendLog(String text) {
File logFile = new File(fileLocation);
if (!logFile.exists()) {
try {
Log.e("file was not created", "file created");
logFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
// BufferedWriter for performance, true to set append to file flag
BufferedWriter buf = new BufferedWriter(new FileWriter(logFile, true)/*,8192*/);
//buf.newLine();
// System.getProperty("line.separator");
buf.write(text);
//System.getProperty("line.separator");
//buf.append("\n");
//buf.write("/\n");
buf.newLine();
buf.close();
} catch (IOException e) {
e.printStackTrace();
}
}