Printwriter does not work on Android?

Asked

Viewed 28 times

1

I’m trying to run this code, but it doesn’t work, from the error in Try{}, in Java it works perfectly.

public void criatxt(){

      String texto = "XXX";

      try{
         PrintWriter arq = new PrintWriter("meudocumento.txt");
         System.out.println("Salvou");
         arq.print(texto);
         arq.close();
      }
      catch(Exception er){
         er.printStackTrace();  
         System.out.println("Salvou: "+ er.getStackTrace());
      }
}

The error in Exception is this: Ljava.lang.Stacktraceelemente;@xxxxxxx

  • PrintWriter works normally on Android. If you are giving error in try, inform in your question which error is giving. If it is a message in logcat, post the text of the message.

  • of that error: Ljava.lang.Stacktraceelemente;@xxxxxxx

  • This error is because you printed er.getStackStrace(). Exchange for er.getMessage() or er.getClass().getName() and say what is being printed. But note that before that you are calling er.printStackTrace() and the complete exception is being printed on the logcat and that’s what we need here, maybe you’re just not able to find.

  • I think the file is being saved in a place that can’t, you know how do I create that txt in a specific place like C:?

  • He is not being saved. He is trying to save but is making an exception, so much so that he printed er.getStackTrace() who returned Ljava.lang.StackTraceElemente;@xxxxxxx. We want to know what the exception is.

  • If you want to save in a specific place, see this question.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.