Announcement

Collapse
No announcement yet.

schreiben in einer textdatei

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    ich habe jetzt mein datei interne gespeichert und kann ich auch auslesen dass funktioniert prima mit folgende code
    [highlight=java] private void save_IP()
    {
    // writing data to a given file
    String string1 = "IP_Adresse";
    String string2 = "IP_Adresse";
    String string3 = "IP_Adresse";
    try {
    FileOutputStream out = openFileOutput("test.txt", Context.MODE_PRIVATE);
    out.write(string1.getBytes());
    out.write(string2.getBytes());
    out.write(string3.getBytes());
    out.flush();
    out.close();
    Toast.makeText(this, "File was generated", Toast.LENGTH_SHORT).show();

    }

    catch (Exception e) {
    Toast.makeText(this, "File cannot be generated", Toast.LENGTH_SHORT).show();

    }

    }

    private void read_IP()
    {
    // reading data to a given file
    int ausgabe;
    StringBuffer strInhalt = new StringBuffer("");
    try {

    FileInputStream in = openFileInput("test.txt");
    while( (ausgabe = in.read()) != -1)
    strInhalt.append((char)ausgabe);
    text.setText(strInhalt.append((char)ausgabe));
    Toast.makeText(this, "File was read", Toast.LENGTH_SHORT).show();

    }

    catch (Exception e) {
    Toast.makeText(this, "File cannot be read", Toast.LENGTH_SHORT).show();

    }

    }[/highlight]
    nachdem ich die funktion save_IP() aufgerufen habe möchte überprüfen ob die file existiert und kommischeweise sagt er dass die file nicht existiert weiß jemand wo das problem liegt ?
    mein code sieht so aus
    [highlight=java]File file = new File("test.txt");
    if(file.exists()) {
    Toast.makeText(this, "file exist", Toast.LENGTH_SHORT).show();
    }
    else {
    Toast.makeText(this, "file don´t exist", Toast.LENGTH_SHORT).show();
    }[/highlight]

    Comment


    • #17
      Also spontan würde ich behaupten, du musst erst einen Mediascan ausführen musst:
      http://developer.android.com/referen...NNER_SCAN_FILE

      Code:
      sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
      Ist die Datei nach einem Neustart da?

      Comment


      • #18
        Der Beitrag ist fast 1 Jahr alt...
        Christian

        Comment


        • #19
          Originally posted by Christian Marquardt View Post
          Der Beitrag ist fast 1 Jahr alt...
          Sorry, nicht darauf geachtet. Naja, vielleicht hilft es ja mal irgendwem

          Comment

          Working...
          X