0

私はテキストファイルを作成し、それにいくつかのデータを書き込んでいます.ファイルに書きたい文字列は正常に書き込まれますが、ファイルに新しい行(\nを使用)を書きたいときはいつでも、そのnotpadファイルにいくつかのボックスが表示されます[ ][]][]。テキストファイルに改行文字を書き込むにはどうすればよいですか。何が間違っているのか教えてください。ここに私のコードがあります。よろしくお願いします。

      try {
        //FileWriter f = new FileWriter("/sdcard/download/possible.txt");
     FileOutputStream fOut = openFileOutput("report.txt",MODE_WORLD_READABLE);
         OutputStreamWriter osw = new OutputStreamWriter(fOut); 
         osw.write("Diet Report"+"\n");
         osw.append("\nFood Calories Consumed \n");
        osw.append(""+SummaryReportActivity.map.keySet());
    osw.append(""+SummaryReportActivity.map.values());
         osw.append("\n");
     osw.append("\nExercise Calories Burnt \n");
    osw.append(""+SummaryReportActivity.exercisemap.keySet());
    osw.append(""+SummaryReportActivity.exercisemap.values());
             osw.append("\n");
             osw.append("\nWeight Recorded \n");
         osw.append(""+SummaryReportActivity.weightmap.keySet());
                             osw.append(""+SummaryReportActivity.weightmap.values());
         osw.append("\n");
         osw.append("\nNet Calories Daily \n");
                             osw.append(""+SummaryReportActivity.netCalorie.keySet());
                             osw.append(""+SummaryReportActivity.netCalorie.values());
         osw.flush();
         osw.close();
        FileInputStream fIn = openFileInput("report.txt");
           InputStreamReader isr = new InputStreamReader(fIn);
           char[] inputBuffer = new char[100];
             isr.read(inputBuffer);
           readString = new String(inputBuffer);

        } catch (IOException e) {
                // TODO Auto-generated catch block
                    e.printStackTrace();
            }


//code to mail that text file as an attachement 
    Intent i=new Intent(Intent.ACTION_SEND);
                        //i.putExtra(Intent.EXTRA_EMAIL,emailaddress.getText().toString());
        i.putExtra(Intent.EXTRA_SUBJECT, "Summary report of your diet");
        i.putExtra(Intent.EXTRA_STREAM, Uri.parse("report.txt"));
        i.setType("text/plain");
           startActivity(i); 
4

1 に答える 1

0

System.getProperty( "line.separator");だと思います。探しているものです。これにより、実行しているプラ​​ットフォームに適した改行文字が取得されます。

この投稿をご覧ください。

于 2012-01-13T11:07:26.243 に答える