List of usage examples for java.io FileNotFoundException getMessage
public String getMessage()
From source file:eu.planets_project.pp.plato.util.FileUtils.java
public static void writeToFile(InputStream in, OutputStream out) throws IOException { try {//from w ww.j a va 2 s.c om byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } } catch (FileNotFoundException ex) { log.debug("Error copying file " + ex.getMessage(), ex); } finally { try { in.close(); } catch (Exception skip) { } try { out.close(); } catch (Exception skip) { } } }
From source file:br.senac.tads.pi3.ghosts.locarsys.dao.Relatorios.java
public static void relatoriosVendas() throws SQLException, ClassNotFoundException { String query = "SELECT FL.NOME_FILIAL, COUNT(FL.NOME_FILIAL) AS QUANTIDADE FROM FILIAL FL " + "INNER JOIN FUNCIONARIO FUNC ON FUNC.ID_FILIAL = FL.ID_FILIAL " + "INNER JOIN ALUGUEL AL ON AL.ID_FUNCIONARIO = FUNC.ID_FUNCIONARIO " + "GROUP BY FL.NOME_FILIAL"; Connection conn = Conexoes.obterConexao(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(query); DefaultCategoryDataset ds = new DefaultCategoryDataset(); while (rs.next()) { ds.addValue(rs.getInt("QUANTIDADE"), "Quantidade", rs.getString("NOME_FILIAL")); }/* w w w.ja v a2 s .com*/ JFreeChart grafico = ChartFactory.createBarChart3D("Relatrio de Aluguis", "Filiais", "Separadas por filiais", ds, PlotOrientation.VERTICAL, true, true, false); try (OutputStream arquivo = new FileOutputStream("ImagensLoCarSys\\vendas.png")) { ChartUtilities.writeChartAsPNG(arquivo, grafico, 800, 600); } catch (FileNotFoundException ex) { System.out.println("" + ex.getMessage()); } catch (IOException ex) { System.out.println("" + ex.getMessage()); } //try (OutputStream arquivo = new FileOutputStream("C:\\Users\\bruno.clopes\\Documents\\NetBeansProjects\\LoCarSys\\target\\LoCarSys-1.0-SNAPSHOT\\ImagensLoCarSys\\vendas.png")) { try (OutputStream arquivo = new FileOutputStream( "C:\\Users\\temp.cas\\Documents\\NetBeansProjects\\LoCarSys\\target\\LoCarSys-1.0-SNAPSHOT\\ImagensLoCarSys\\vendas.png")) { ChartUtilities.writeChartAsPNG(arquivo, grafico, 800, 600); } catch (FileNotFoundException ex) { System.out.println("" + ex.getMessage()); } catch (IOException ex) { System.out.println("" + ex.getMessage()); } }
From source file:cz.zcu.kiv.eegdatabase.wui.components.utils.FileUtils.java
/** * Prepare byte array from file./*from w w w . ja va 2 s .c o m*/ * * @param file * @return */ public static byte[] getFileContent(File file) { if (file == null) { return new byte[0]; } else { try { FileInputStream fileInputStream = new FileInputStream(file); byte[] byteArray = IOUtils.toByteArray(fileInputStream); fileInputStream.close(); return byteArray; } catch (FileNotFoundException e) { log.error(e.getMessage(), e); return new byte[0]; } catch (IOException e) { log.error(e.getMessage(), e); return new byte[0]; } } }
From source file:br.senac.tads.pi3.ghosts.locarsys.dao.Relatorios.java
public static void relatoriosDisponibilidade() throws SQLException, ClassNotFoundException { String query = "SELECT FL.NOME_FILIAL, COUNT(FL.NOME_FILIAL) AS QUANTIDADE FROM CARRO CA " + "INNER JOIN FILIAL FL ON FL.ID_FILIAL = CA.ID_FILIAL " + "WHERE CA.DISPONIBILIDADE_CARRO = '1' " + "GROUP BY FL.NOME_FILIAL"; Connection conn = Conexoes.obterConexao(); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(query); DefaultCategoryDataset ds = new DefaultCategoryDataset(); while (rs.next()) { ds.addValue(rs.getInt("QUANTIDADE"), "Quantidade", rs.getString("NOME_FILIAL")); }/* w w w . ja va2 s.c om*/ /*File fg = new File("C:\\Users\\bruno.lopes.KRONMED\\Documents\\NetBeansProjects\\LoCarSys\\src\\main\\webapp\\ImagensLoCarSys\\disponibilidade.png"); fg.delete();*/ JFreeChart grafico = ChartFactory.createBarChart3D("Relatrio de Disponibilidade", "Filiais", "Separados por filiais", ds, PlotOrientation.VERTICAL, true, true, false); //try (OutputStream arquivo = new FileOutputStream("C:\\Users\\bruno.clopes\\Documents\\NetBeansProjects\\LoCarSys\\target\\LoCarSys-1.0-SNAPSHOT\\ImagensLoCarSys\\disponibilidade.png")) { try (OutputStream arquivo = new FileOutputStream("ImagensLoCarSys\\disponibilidade.png")) { ChartUtilities.writeChartAsPNG(arquivo, grafico, 800, 600); } catch (FileNotFoundException ex) { System.out.println("" + ex.getMessage()); } catch (IOException ex) { System.out.println("" + ex.getMessage()); } //try (OutputStream arquivo = new FileOutputStream("C:\\Users\\bruno.clopes\\Documents\\NetBeansProjects\\LoCarSys\\target\\LoCarSys-1.0-SNAPSHOT\\ImagensLoCarSys\\disponibilidade.png")) { try (OutputStream arquivo = new FileOutputStream( "C:\\Users\\temp.cas\\Documents\\NetBeansProjects\\LoCarSys\\target\\LoCarSys-1.0-SNAPSHOT\\ImagensLoCarSys\\disponibilidade.png")) { ChartUtilities.writeChartAsPNG(arquivo, grafico, 800, 600); } catch (FileNotFoundException ex) { System.out.println("" + ex.getMessage()); } catch (IOException ex) { System.out.println("" + ex.getMessage()); } }
From source file:com.clustercontrol.jobmanagement.util.JobmapIconImageUtil.java
/** * ?/*w w w . j av a 2s . c o m*/ * @param filepath * @throws Exception */ private static byte[] getFileData(String filepath) throws Exception { File file = new File(filepath); String filename = file.getName(); int filesize = (int) file.length(); if (filesize > MAX_FILESIZE) { m_log.warn("getFileData(), file size is too large"); throw new Exception(Messages.getString("message.job.143")); } byte[] filedata = null; /* * */ FileInputStream stream = null; try { stream = new FileInputStream(filepath); filedata = new byte[filesize]; int readsize = stream.read(filedata, 0, filesize); m_log.debug("UploadImage readsize = " + readsize + ", filesize = " + filesize); m_log.debug("path=" + filepath + ", name=" + filename); } catch (FileNotFoundException e) { m_log.warn("getFileData(), " + e.getMessage(), e); throw new Exception(Messages.getString("file.not.found"), e); } catch (Exception e) { m_log.warn("getFileData(), " + e.getMessage(), e); throw e; } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { m_log.warn("getFileData(), " + e.getMessage(), e); } stream = null; } } return filedata; }
From source file:Main.java
/** * Reads data from specified file./*from w ww . j av a 2s . c om*/ * @param path Path to file. * @return 2-dimensional array of data. */ public static ArrayList<ArrayList<String>> loadFile(String path) { FileReader fr = null; String line = ""; ArrayList<ArrayList<String>> dataArray = new ArrayList<>(); try { fr = new FileReader(path); } catch (FileNotFoundException e) { // TODO Auto-generated catch block System.out.println(e.getMessage()); } BufferedReader br = new BufferedReader(fr); ArrayList<String> tokens = new ArrayList<>(); try { while ((line = br.readLine()) != null) { tokens = parseLine(line); dataArray.add(tokens); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { fr.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return dataArray; }
From source file:Main.java
/** * Reads data from specified file.//from ww w. ja v a 2 s . c om * @param file A file to read from. * @return 2-dimensional array of data. */ public static ArrayList<ArrayList<String>> loadFile(File file) { FileReader fr = null; String line = ""; ArrayList<ArrayList<String>> dataArray = new ArrayList<>(); try { fr = new FileReader(file); } catch (FileNotFoundException e) { // TODO Auto-generated catch block System.out.println(e.getMessage()); } BufferedReader br = new BufferedReader(fr); ArrayList<String> tokens = new ArrayList<>(); try { while ((line = br.readLine()) != null) { tokens = parseLine(line); dataArray.add(tokens); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { fr.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return dataArray; }
From source file:com.aurel.track.lucene.index.associatedFields.LuceneFileExtractor.java
public static Reader getReader(File file) { Reader reader = null;/*from www . ja va 2s . co m*/ if (file == null || !file.exists()) { return null; } try { reader = new FileReader(file); } catch (FileNotFoundException e) { LOGGER.info("File " + file.getName() + " not found. " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); } reader = new BufferedReader(reader); return reader; }
From source file:net.orpiske.ssps.sdm.main.Main.java
/** * Initializes the configuration object// ww w .j a v a2 s .c om */ private static void initConfig() { try { ConfigurationWrapper.initConfiguration(Constants.SDM_CONFIG_DIR, Constants.CONFIG_FILE_NAME); } catch (FileNotFoundException e) { System.err.println(e.getMessage()); System.exit(-3); } catch (ConfigurationException e) { System.err.println(e.getMessage()); System.exit(-3); } try { RepositorySettings.initConfiguration(); } catch (SspsException e) { e.printStackTrace(); System.err.println(e.getMessage()); System.exit(-3); } }
From source file:com.aurel.track.exchange.UploadHelper.java
/** * Upload the file in a person and type specific directory * @return/* w w w .j a va2 s. com*/ */ public static String upload(File uploadFile, String uploadFileFileName, String targetPath, Locale locale, String successResult) { InputStream inputStream; try { inputStream = new FileInputStream(uploadFile); } catch (FileNotFoundException e) { LOGGER.error("Getting the input stream for the uploaded file failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); JSONUtility.encodeJSON(ServletActionContext.getResponse(), JSONUtility.encodeJSONFailure(LocalizeUtil .getLocalizedTextFromApplicationResources("admin.actions.importTp.err.failed", locale))); return null; } UploadHelper.ensureDir(targetPath); File targetFile = new File(targetPath, uploadFileFileName); if (targetFile.exists()) { //if the file exists (as a result of a previous import) then delete it targetFile.delete(); } try { OutputStream outputStream = new FileOutputStream(targetFile); byte[] buf = new byte[1024]; int len; while ((len = inputStream.read(buf)) > 0) { outputStream.write(buf, 0, len); } inputStream.close(); outputStream.close(); } catch (Exception e) { LOGGER.error("Saving the file " + uploadFileFileName + " to the temporary directory " + targetPath + " failed with " + e.getMessage()); LOGGER.debug(ExceptionUtils.getStackTrace(e)); JSONUtility.encodeJSON(ServletActionContext.getResponse(), JSONUtility.encodeJSONFailure(LocalizeUtil .getLocalizedTextFromApplicationResources("admin.actions.importTp.err.failed", locale))); return null; } return successResult; }