Jump to content

So I am making an android app and I want to write a string to a file. The problem is that whenever I do that, the file is empty. I have checked and the string I input in the function is not empty. Anyway, here is the code responsible for the write operation:

    public void writeToFile(String text, String dir)    {        try        {            FileOutputStream out = new FileOutputStream(new File(dir));            PrintWriter fileOut = new PrintWriter(out);            fileOut.print(text);            out.close();            fileOut.close();        }catch(Exception e)        {                    }    }

MacBook Pro 15' 2018 (Pretty much the only system I use)

Link to comment
https://linustechtips.com/topic/401645-problem-with-android-app/
Share on other sites

Link to post
Share on other sites

Grammar nazis are people too!
Treat your local grammar nazi nicely and he might teach you a thing or two. (Note that I'm Belgian and not a native English speaker.)
Chivalry isn't dead!

Link to comment
https://linustechtips.com/topic/401645-problem-with-android-app/#findComment-5422442
Share on other sites

Link to post
Share on other sites

I fixed it! When I should have used File out = new File(directory, filename); Now it's all fine :D

MacBook Pro 15' 2018 (Pretty much the only system I use)

Link to comment
https://linustechtips.com/topic/401645-problem-with-android-app/#findComment-5423615
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×