Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    salvataggio su file [java]

    Ho provato ad utilizzare il seguente codice per determinare se un file esiste, purtroppo mi dice cannot resolve symbol method exists()...potete aiutarmi? Thanx.

    import java.io.*;

    class Output {
    public static void main(String args[]) {
    try {
    int n = 0;
    String filename = new String("Output " + n + ".txt");
    while (filename.exists() == false) {
    n++;
    }
    PrintWriter out = new PrintWriter(new FileWriter("filename"));
    out.print("test writing");
    out.close();
    }
    catch(Exception e) {
    System.err.println("ERROR: " + e);
    }
    }
    }
    Walk fast, chew slowly.
    "We used students as subjects because rats are expensive and you get too attached to them"

  2. #2
    Utente di HTML.it L'avatar di floyd
    Registrato dal
    Apr 2001
    Messaggi
    3,837
    File filename = new File("Output " + n + ".txt");
    while (filename.exists())

  3. #3
    ah, che stupido, chiaramente while deve essere true ed é un file che deve esistere. Con queste modifiche mi compila correttamente, perķ ad un primo tentativo mi crea un file filename, ad un secondo non succede piú niente, dos non finisce neanche di eseguire il programma. Modificando la linea
    PrintWriter out = new PrintWriter(new FileWriter("Output " + n + ".txt"));
    anche se riesco ad ottenere un file di output Output 0.txt so di non aver risolto niente, e comunque al secondo tentativo is blocca. Cosa sto sbagliando?
    Walk fast, chew slowly.
    "We used students as subjects because rats are expensive and you get too attached to them"

  4. #4
    Utente di HTML.it L'avatar di floyd
    Registrato dal
    Apr 2001
    Messaggi
    3,837
    File filename= new File("Output " + n + ".txt");
    while (filename.exists()) {
    ...
    filename= new File("Output " + n + ".txt");
    }

  5. #5
    :metallica :metallica :metallica floyd una certezza ormai...poi sto anche risolvendo il mio problemino col creare database quindi ci siamo...
    Walk fast, chew slowly.
    "We used students as subjects because rats are expensive and you get too attached to them"

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.