第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

Java SWT 文件保存

Java SWT 文件保存

回首憶惘然 2021-08-13 16:55:59
我在保存文件時(shí)遇到了問題,因?yàn)槲乙呀?jīng)搜索過,我寫的很好,除了一件事,文件沒有真正創(chuàng)建。缺少什么?        Button btnExport = new Button(composite_1, SWT.NONE);    btnExport.addSelectionListener(new SelectionAdapter() {        @Override        public void widgetSelected(SelectionEvent e) {            FileDialog fileSave = new FileDialog(pmComp, SWT.SAVE);            fileSave.setFilterNames(new String[] {"CSV"});            fileSave.setFilterExtensions(new String[] {"*.csv"});            fileSave.setFilterPath("c:\\"); // Windows path            fileSave.setFileName("your_file_name.csv");            fileSave.open();            System.out.println("File Saved as: " + fileSave.getFileName());        }    });    btnExport.setBounds(246, 56, 75, 40);    btnExport.setText("Export");
查看完整描述

3 回答

?
牛魔王的故事

TA貢獻(xiàn)1830條經(jīng)驗(yàn) 獲得超3個(gè)贊

從FileDialog:


此類的實(shí)例允許用戶瀏覽文件系統(tǒng)并 選擇或輸入文件名。


該對話框不會自行創(chuàng)建文件,您必須檢索所選文件名,然后創(chuàng)建文件。


例如


String name = fileSave.getFileName();

File file = new File(name);

file.createNewFile();


查看完整回答
反對 回復(fù) 2021-08-13
?
斯蒂芬大帝

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊

FileDialog僅用于選擇文件保存的位置。它并沒有真正創(chuàng)建或?qū)懭胛募?你必須這樣做。


所以


String savePath = fileSave.open();


// TODO your code to write the file to savePath


查看完整回答
反對 回復(fù) 2021-08-13
?
幕布斯7119047

TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊

import java.io.File;

import java.io.IOException;


import org.eclipse.swt.SWT;

import org.eclipse.swt.events.SelectionAdapter;

import org.eclipse.swt.events.SelectionEvent;

import org.eclipse.swt.layout.GridData;

import org.eclipse.swt.layout.GridLayout;

import org.eclipse.swt.widgets.Button;

import org.eclipse.swt.widgets.Composite;

import org.eclipse.swt.widgets.Display;

import org.eclipse.swt.widgets.FileDialog;

import org.eclipse.swt.widgets.Shell;


public class Snippet {

    public static void main(String[] args) {


        Display display = new Display();

        Shell shell = new Shell(display);

        shell.setLayout(new GridLayout(1, false));


        Composite composite = new Composite(shell, SWT.NONE);

        composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

        composite.setLayout(new GridLayout(1, false));


        Button btnExport = new Button(composite, SWT.NONE);

        btnExport.addSelectionListener(new SelectionAdapter() {

            @Override

            public void widgetSelected(SelectionEvent e) {


                FileDialog fileSave = new FileDialog(shell, SWT.SAVE);

                fileSave.setFilterNames(new String[] { "CSV" });

                fileSave.setFilterExtensions(new String[] { "*.csv" });

                fileSave.setFilterPath("C:\\"); // Windows path

                fileSave.setFileName("your_file_name.csv");

                String open = fileSave.open();

                File file = new File(open);

                try {

                    file.createNewFile();

                    System.out.println("File Saved as: " + file.getCanonicalPath());

                } catch (IOException e1) {

                    e1.printStackTrace();

                }

            }

        });

        btnExport.setBounds(246, 56, 75, 40);

        btnExport.setText("Export");


        shell.pack();

        shell.open();

        while (!shell.isDisposed()) {

            if (!display.readAndDispatch())

                display.sleep();

        }


    }

}


查看完整回答
反對 回復(fù) 2021-08-13
  • 3 回答
  • 0 關(guān)注
  • 203 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號