SCRIVE una stringa di testo su un file
codice:
import java.io.*;
class scrivi{
public static void main(String args[]) throws Exception{
String source = "Output su file in Java\n";
char buffer[] = new char[source.length()];
source.getChars(0, source.length(), buffer, 0);
FileWriter f = new FileWriter("fileProva.txt");
f.write(buffer);
f.close();
}
}
LEGGE quello che hai scritto nell'esempio sopra:
codice:
import java.io.*;
class leggi{
public static void main(String args[]) throws Exception{
int i;
InputStream f = new FileInputStream("fileProva.txt");
do{
i = f.read();
if(i != -1) System.out.print((char) i);
}while(i != -1);
f.close();
}
}
ciao