风机的数据的导入

		JButton btnNewButton = new JButton("导入");
		btnNewButton.addMouseListener(new MouseAdapter() {
			private FileOutputStream fos;
			private FileInputStream fis;
			private BufferedInputStream bis;
			private BufferedOutputStream bos;

			@Override
			public void mouseClicked(MouseEvent paramMouseEvent) {
				try {
					if (filePathText.getText() != null) {
						File file = new File(filePathText.getText());
						// FileInputStream fis = new FileInputStream(file);

						

						String name = file.getName();
						System.out.println("name " + name);
						String outfilename = IAppConstants.fanpath
								+ name.substring(0, name.indexOf(".")) + ".dat";
						System.out.println(outfilename);

						File outfile = new File(outfilename);
						if (outfile.exists()) {
							int  con = JOptionPane.showConfirmDialog(null, "文件已存在,继续导入?", "导入错误",
									JOptionPane.YES_NO_CANCEL_OPTION,JOptionPane.INFORMATION_MESSAGE);
							if(con>0)
								return;
						}
						fos = new FileOutputStream(outfile);
						fis = new FileInputStream(file);
						bis = new BufferedInputStream(fis);
						bos = new BufferedOutputStream(fos);

						int i;
						byte[] buf = new byte[2048];
						while ((i = bis.read(buf)) != -1) {
							fos.write(buf, 0, i);
						}
						
						chartParentPanel.removeAll();
						double[][] dataArr = GetFanArr.getFanDataArr(file);

						chart = createChart(dataArr);

						chartParentPanel.setLayout(new BorderLayout(0, 0));
						chartPanel = new ChartPanel(chart);
						chartPanel.setPreferredSize(new Dimension(400, 360));
						chartPanel.setFillZoomRectangle(true);
						chartParentPanel.add(chartPanel, BorderLayout.CENTER);

						chartPanel.revalidate();
						;
						chartPanel.repaint();
						;
						Object[][] obDataArr = toObdata(dataArr);
						dtm = (DefaultTableModel) fanTable.getModel();
						dtm.setDataVector(obDataArr, columnNames);

						fanTable.repaint();
						
						
						
						

						JOptionPane.showMessageDialog(null, file + "导入成功,",
								"提示", JOptionPane.INFORMATION_MESSAGE);

					}
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					JOptionPane.showMessageDialog(null, "请检查excel表格", "错误",
							JOptionPane.ERROR_MESSAGE);

				} finally {
					try {
						fis.close();
						fos.flush();
						fos.close();
						bis.close();
						bos.close();
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}

			}
		});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值