List of usage examples for java.awt Desktop open
public void open(File file) throws IOException
From source file:view.ViewRequestedFileStatus.java
private void downloadSelectedFileWithDecryption() { String requestedFilePath = requested_files_table.getValueAt(requested_files_table.getSelectedRow(), 6) .toString();/*from w w w.j ava2s .c o m*/ String requestedFileName = requested_files_table.getValueAt(requested_files_table.getSelectedRow(), 1) .toString(); String eid = requested_files_table.getValueAt(requested_files_table.getSelectedRow(), 7).toString(); System.out.println(requestedFilePath); File fromFile = new File(Configuration.dataCloud + requestedFilePath); try { String readFileToString = FileUtils.readFileToString(fromFile); // kakes String qery = "select private_key,master_key,secret_key from tbl_file_encryption_logs where encryption_id=" + eid; ResultSet select = new Dbcon().select(qery); if (select.next()) { String private_key = select.getString("private_key"); String master_key = select.getString("master_key"); String secret_key = select.getString("secret_key"); System.out.println("private_key " + private_key); System.out.println("master_key " + master_key); System.out.println("secret_key " + secret_key); File privateKey = new File(Configuration.allKeys + private_key); File masterKey = new File(Configuration.allKeys + master_key); File secretKey = new File(Configuration.allKeys + secret_key); if (privateKey.exists() && secretKey.exists() && privateKey.exists()) { String p_key = "0"; String m_key = "0"; String s_key = "0"; try { p_key = FileUtils.readFileToString(privateKey); m_key = FileUtils.readFileToString(masterKey); s_key = FileUtils.readFileToString(secretKey); } catch (Exception e) { } try { ENC.setPrivateKey(Integer.parseInt(p_key)); ENC.setMasterKey(Integer.parseInt(m_key)); ENC.setSecretKey(Integer.parseInt(s_key)); } catch (Exception e) { } byte[] dataByteArray = ENC.decodeData(readFileToString); File temporaryFileDirectory = new File( Configuration.temporaryFilePath + System.currentTimeMillis()); if (temporaryFileDirectory.mkdir()) { FileOutputStream dataOutFile = new FileOutputStream(temporaryFileDirectory.getPath() + "/" + requestedFileName + "." + FilenameUtils.getExtension(requestedFilePath)); dataOutFile.write(dataByteArray); dataOutFile.close(); try { Desktop desktop = Desktop.getDesktop(); desktop.open(temporaryFileDirectory); } catch (Exception e) { JOptionPane.showMessageDialog(rootPane, "Could not open the file. Please check directory " + temporaryFileDirectory); } } else { JOptionPane.showMessageDialog(rootPane, "Could not get file permission in computer to make new folder at " + temporaryFileDirectory); } } else { JOptionPane.showMessageDialog(rootPane, "All the keys are not found. Could not decrypt the file"); } } else { JOptionPane.showMessageDialog(rootPane, "Sone could not decrypt the file, please try after some time"); return; } download_button.setEnabled(false); } catch (Exception ee) { ee.printStackTrace(); } }