How can i setParth for new File use JFilechose , save dialog ?

Posted by tiendv on Stack Overflow See other posts from Stack Overflow or by tiendv
Published on 2010-05-12T14:11:08Z Indexed on 2010/05/12 14:14 UTC
Read the original article Hit count: 338

Filed under:
|

I have a dialog use Jfilechose, when i save a file by use FileOutputStream to create a file.txt to save in path which user want . But i have problem that it alway save in c:/user/Document Check my code

DownLoadDialog downloadDialog = new DownLoadDialog(); int result = downloadDialog.showSaveDialog(queryPanel); if(result == downloadDialog.APPROVE_OPTION) {

        File file = downloadDialog.getSelectedFile();
        //String parth =file.getPath();
        //System.out.println(parth);
        //if(file.exists()) {
        //  int response = JOptionPane.showConfirmDialog (null,"Overwrite existing file?","Confirm Overwrite",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE);
        //   if(response == JOptionPane.OK_OPTION) {}
        //} else {
            if(resultGoogleSearch > 0) {
            {
                String parth = new File(downloadDialog.getSelectedFile().getAbsolutePath().concat(".txt")).toString();
                System.out.println(parth);

                for(int i=0;i<resultGoogleSearch;i++)
                {
                    String[] temp = googleSearchResult.get(i).split("<br>");
                    //String resultURL = temp[0];
                    //File dir = downloadDialog.getCurrentDirectory();  
                    try{
                            FileOutputStream googleReuslt = new FileOutputStream( downloadDialog.getSelectedFile().getAbsolutePath()+".txt" );
                            OutputStreamWriter writer = new OutputStreamWriter(googleReuslt);
                            BufferedWriter buffer = new BufferedWriter(writer);
                            writer.write(temp[0]);  
                            writer.close();
                            buffer.close();
                        } catch (FileNotFoundException fEx){

                        } catch(IOException ioEx) {

                        }                   
                }
             }
             JOptionPane.showMessageDialog(IDRSApplication.idrsJFrame, IDRSResourceBundle.res.getString("successful"));
        }

problem is here : why can't i set parth for new file ?

FileOutputStream googleReuslt = new FileOutputStream( downloadDialog.getSelectedFile().getAbsolutePath()+".txt" );
                            OutputStreamWriter writer = new OutputStreamWriter(googleReuslt);
                            BufferedWriter buffer = new BufferedWriter(writer);
                            writer.write(temp[0]);  
                            writer.close();
                            buffer.close();

© Stack Overflow or respective owner

Related posts about java

Related posts about swing