如何将excel文件写入可选的文件位置?

我正在使用GWT进行项目。 在button单击我想要将Excel文件保存到用户定义的文件位置。 是否有可能提示用户的文件位置保存?

所以,而不是保存在C:\新build文件夹\我想让用户select..

FileOutputStream out = new FileOutputStream("C:\\New folder\\purchase-order.xlsx"); wb.write(out); out.close(); 

涉及button的前端看起来像这样。

 Button getPurchaseOrderForAllPickedItems = new Button("Get Purchase Order for all items selected", new ClickHandler() { public void onClick(ClickEvent event) { HashMap<String, ArrayList<Item>> exportFile = extracted(); sendListToServerForExport(exportFile); } 

sendListToServerForExport方法如下所示:

 private void sendListToServerForExport(HashMap<String, ArrayList<Item>> exportMap) { if (stockPriceSvc == null) { stockPriceSvc = GWT.create(PurchaseOrderService.class); } AsyncCallback<String> callback = new AsyncCallback<String>() { @Override public void onFailure(Throwable caught) { // TODO Auto-generated method stub } @Override public void onSuccess(String result) { Window.alert(result); } }; stockPriceSvc.createExcelExportFile(exportMap, callback); } 

服务实现中的方法如下所示:

 public String createExcelExportFile( HashMap<String, ArrayList<Item>> exportMap) { controller.createFileToExport(exportMap); return "Succes"; } 

除非你留下一些重要的细节,否则应该很简单。 只要提示用户input位置,并使用扫描仪或提示将input作为string。 我将在这里张贴一些示例代码…

 import java.util.Scanner; public class ReadConsoleScanner { public static void main(String[] args) { System.out.println("Enter something here : "); String sWhatever; Scanner scanIn = new Scanner(System.in); sWhatever = scanIn.nextLine(); scanIn.close(); System.out.println(sWhatever); } }