java - How to save file.txt with JFileChooser? -


I'm developing Notepad project, know how to save file.txt, my problem is, I Keep the file after opening JFileChooser, select local, where is the intent to save, but if saved after JFileChoose will open again again. I do not save as I want to save

  Jeffery Fleur FC = New Jeffiele (); Int resp = fc.showSaveDialog (FC); If (resp == JFileChooser.APPROVE_OPTION) {PrintStream fileOut = null; Try the file {file file = fc.get}; FileOut = new printstream (file); FileOut.print (txtArea.getText ()); } Hold (FileNotFoundException pre) {Logger.getLogger (frmNotePad.class.getName ()). Logs (level SESEE, ANNEL, X); } Finally {fileOut.close (); }    

Change the workflow to you

Actually, when you first save the file, you need to keep the context of the file that you saved ...

 < Code> public class ... {private file currentFile;   

Now, when you save the file, you will need to check whether currentFile is null or not Null , you ask the user to select a file, otherwise, you can go ahead and save the file and save ...

  if (currentFile = = Null) {JFileChooser fc = new JFileChooser (); Int resp = fc.showSaveDialog (FC); If (resp == JFileChooser.APPROVE_OPTION) {currentFile = fc.get was selected file (); }} // is used to ensure that the user did not cancel JFileChooser if (currentFile! = Null) {PrintStream fileOut = null; Try {fileOut = new PrintStream (file); FileOut.print (txtArea.getText ()); } Hold (IOException pre) {Logger.getLogger (frmNotePad.class.getName ()). Log (Level.SEVERE, null, ex); } Finally {try {fileOut.close ()}} Hold (IOException exp) {}}    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -