hi ,
i have a little confusion.. i want to write a string in a text file which should be dynamically saved by the saveDialog i have done this task statically.. means file with specified file name is created and text is also written from jTextArea.. but i wnt to save this file on my given location and with my given name.. can u please guide me in this regard?? below is code:
do{
String fileData=jTextArea1.getText();
byte buf[]=fileData.getBytes();
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Text/fasta files", ".txt", ".fasta");
chooser.setFileFilter(filter);
int returnVal = chooser.showSaveDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("inside try after retVal");
try{
//OutputStream f2=new FileOutputStream("filename.txt");
OutputStream f2=new FileOutputStream("file.txt");
f2.write(buf);
f2.close();
} catch (IOException ex) {
Logger.getLogger(CreatingFile.class.getName()).log(Level.SEVERE, null, ex);
}
} else {
return null;
} //else ends
// TODO add your handling code here:
}while(true);