1 回答
TA贡献1794条经验 获得超8个赞
希望这可能对你有用。您可以格式化数据,例如:
public String formatData(List<User> users) {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < users.size(); i++) {
stringBuilder.append("##\n");
stringBuilder.append("id:" + user.getId() + "\n");
stringBuilder.append("heatUsage:" + user.getHeatUsage() + "\n");
stringBuilder.append("waterUsage:" + user.getWaterUsage() + "\n");
}
return stringBuilder.toString();
}
并写入文件:
private void writeToFile(String data,Context context) {
try {
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(context.openFileOutput("filename.txt", Context.MODE_PRIVATE));
outputStreamWriter.write(data);
outputStreamWriter.close();
}
catch (IOException e) {
Log.e("Exception", "File write failed: " + e.toString());
}
}
添加回答
举报