How about friends, I am developing an application that generates a text file ( .txt
) with multiple lines obtained from a DB, to then send through an email, the problem is when the email is received and when viewing the file on a PC, the text appears in a single line, when viewing the same file on the cell phone if it has the line break.
This is the code I use to concatenate and save to a text file:
BufferedWriter fileWritter = new BufferedWriter(new FileWriter("/sdcard/arhivos/"+currentDate)); //ubicacion y nombre del archivo
while(c.moveToNext()){
registros = String.format(codigoReloj + c.getString(0).toString() + c.getString(1).toString().replace("/", "") + c.getString(2).toString().replace(":", "")+"\n");
fileWritter.append( registros );
fileWritter.flush();
registros = "";
}
fileWritter.close();
This is the code I use to send the file
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("message/rfc822");
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
emailIntent.putExtra(Intent.EXTRA_CC, cc);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, asunto);
emailIntent.putExtra(Intent.EXTRA_TEXT, mensaje);
emailIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://"+"/storage/sdcard0/archivos/"+ asunto));
emailIntent.setType("text/plain"); //indicamos el tipo de dato
startActivity(Intent.createChooser(emailIntent, "Email "));
I already tried to generate the file with:
writer.newLine();
System.getProperty("line.separator");
String.format("%n");
With these options, the line breaks are displayed on the cell phone, after sending it and viewing the file on a PC, the text appears in a single line.