簡體   English   中英

在任何位置使用JFileChooser保存文件

[英]saving file using JFileChooser at any location

你好,我正在嘗試將文件保存在Jfilechooser指定的位置,現在的情況是,當用戶單擊“保存”時,將在項目方向上以名稱標題創建文件,但是我需要給用戶選擇保存文件的位置,並且使用JFileChooser選擇他喜歡的名稱

if(buttonPressed.equals(save)){

         File myFile = new File("title");
         final JFileChooser fc = new JFileChooser();
         int returnVal = fc.showSaveDialog(null);
         fc.setSelectedFile(myFile);
         if (returnVal == JFileChooser.APPROVE_OPTION) {

            try (PrintWriter writer = new PrintWriter(myFile)) {   

            for (int i =0 ; i< cModel.getRowCount(); i++)
            {
               sData.add(cModel.getValueAt(i, 1).toString());
               eData.add(cModel.getValueAt(i, 2).toString());
               tData.add(cModel.getValueAt(i, 3).toString());
               writer.println(i+1 + "\n");
               writer.println(sData.get(i)+" --> " + eData.get(i));
               writer.println(tData.get(i));
               writer.println("\n");
            }
            }catch(FileNotFoundException ioEx){

            } 

         }

         }

嘗試

JFrame choose = new JFrame();
choose.setTitle("Save To ...");
final JFileChooser fc = new JFileChooser();
int returnVal = fc.showSaveDialog(choose);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM