ecco a cosa sono arrivo (l'ho fatto con una applet)
però nn mi funzionacodice:import java.awt.event.KeyListener; import java.awt.event.KeyEvent; import java.awt.*; import java.applet.*; import java.io.*; public class testo extends Applet { TextArea TA=new TextArea(); Label L1=new Label(); Label L2=new Label(); public void init() { add(L1,BorderLayout.NORTH); add(TA,BorderLayout.CENTER); add(L2,BorderLayout.SOUTH); L1.setText("Inserisci un testo da salvare su file. ENTER per salvare"); TA.addKeyListener(new MyKeyListener()); } public class MyKeyListener implements KeyListener { public void keyPressed(KeyEvent e) { } public void keyReleased(KeyEvent e) { int valore=e.getKeyCode(); if (valore==10) { new text(); } } public void keyTyped(KeyEvent e) { } } public class text { public void text(String[] args) throws IOException { try { PrintStream ps = new PrintStream( new FileOutputStream("testosalvato.txt") ); ps.println(TA.getText()); ps.close(); L2.setText("Testo salvato in testosalvato.txt"); } catch (Exception f) { f.printStackTrace(); } } } }
help me
_____________________________________________
per ora va benissimo in out e non in app
_____________________________________________
intendevo che tutte le volte che salvo su file lo riscrivo da zero e non accodo al vechio testo (scrittura in append)

Rispondi quotando