"Resolved" Written file with blanks at the end
<p>I'm creating a class to manage text files. I have a method to write and an other to read my file :</p>

<pre><code>public static void writeFiles(Context context, String nomFichier, String content, char mode) {

    FileOutputStream fOut = null; 
    OutputStreamWriter osw = null; 

    try {
        if (mode == 'd') {
            context.deleteFile(nomFichier);
        } else {        
            fOut = context.openFileOutput(nomFichier, Context.MODE_APPEND);       
            osw = new OutputStreamWriter(fOut); 
            osw.write(content); 
            osw.flush();
        }
    } catch (Exception e) {       
        Toast.makeText(context, "Message not saved",Toast.LENGTH_SHORT).show(); 
    } finally { 
        try { 
            osw.close(); 
            fOut.close(); 
        } catch (IOException e) { 
            Toast.makeText(context, "Message not saved",Toast.LENGTH_SHORT).show(); 
        } 
    } 
}
</code></pre>

<p>When I create a file, it is filled with few empty lines. I want to set the content of my file into an EditText, so I don't want the blanks.
How can I create a file without blanks?</p>

<p>Thx, korax.</p>

<p>EDIT :</p>

<p>I use trim(), suggested by appserv and acj, but in the read function instead of write function. It works fine, thx you!</p>

<pre><code>public static String readFile(Context context, String fileName) {

    FileInputStream fIn = null; 
    InputStreamReader isr = null; 
    char[] inputBuffer = new char[255]; 
    String content = null;

    try { 
        fIn = context.openFileInput(fileName);       
        isr = new InputStreamReader(fIn); 
        isr.read(inputBuffer); 
        content = new String(inputBuffer);
    } catch (Exception e) {       
        //Toast.makeText(context, "Message not read",Toast.LENGTH_SHORT).show(); 
    } 
    finally { 
        try {               
            isr.close(); 
            fIn.close(); 
        } catch (IOException e) { 
            //Toast.makeText(context, "Message not read",Toast.LENGTH_SHORT).show(); 
        } 
    }
    return content.trim();
}
</code></pre>
