Example usage for java.io FileNotFoundException getMessage

List of usage examples for java.io FileNotFoundException getMessage

Introduction

In this page you can find the example usage for java.io FileNotFoundException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:Main.java

public static boolean saveDocument(String fileName, Document doc) {
    System.out.println("Saving XML file... " + fileName);
    // open output stream where XML Document will be saved
    File xmlOutputFile = new File(fileName);
    FileOutputStream fos;/*w w  w . j  a  v  a2  s  . com*/
    Transformer transformer;
    try {
        fos = new FileOutputStream(xmlOutputFile);
    } catch (FileNotFoundException e) {
        System.out.println("Error occured: " + e.getMessage());
        return false;
    }
    // Use a Transformer for output
    TransformerFactory transformerFactory = TransformerFactory.newInstance();
    try {
        transformer = transformerFactory.newTransformer();
    } catch (TransformerConfigurationException e) {
        System.out.println("Transformer configuration error: " + e.getMessage());
        return false;
    }
    DOMSource source = new DOMSource(doc);
    StreamResult result = new StreamResult(fos);
    // transform source into result will do save
    try {
        transformer.transform(source, result);
    } catch (TransformerException e) {
        System.out.println("Error transform: " + e.getMessage());
    }

    return true;
}

From source file:Main.java

public static void storeImage(Bitmap image, String name) {
    if (DEBUG) {/*w w  w  .j  a v a  2s .c  o  m*/
        String TAG = "MobileODR";
        File pictureFile = getOutputMediaFile(name);
        if (pictureFile == null) {
            Log.d(TAG, "Error creating media file, check storage permissions: ");// e.getMessage());
            return;
        }
        try {
            FileOutputStream fos = new FileOutputStream(pictureFile);
            image.compress(Bitmap.CompressFormat.PNG, 90, fos);
            fos.close();
        } catch (FileNotFoundException e) {
            Log.d(TAG, "File not found: " + e.getMessage());
        } catch (IOException e) {
            Log.d(TAG, "Error accessing file: " + e.getMessage());
        }
    }
}

From source file:Main.java

public static <T> T fromXml(File xmlPath, Class<T> type) {
    BufferedReader reader = null;
    StringBuilder sb = null;// w w  w . j  a v  a 2  s . com
    try {
        reader = new BufferedReader(new InputStreamReader(new FileInputStream(xmlPath), ENCODING));
        String line = null;
        sb = new StringBuilder();
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
    } catch (FileNotFoundException e) {
        throw new IllegalArgumentException(e.getMessage());
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                //ignore
            }
        }
    }
    return fromXml(sb.toString(), type);
}

From source file:com.googlecode.t7mp.util.ZipUtil.java

public static void unzip(File war, File destination) {
    try {// www. j  a va  2  s .co  m
        unzip(new FileInputStream(war), destination);
    } catch (FileNotFoundException e) {
        throw new TomcatSetupException(e.getMessage(), e);
    }
}

From source file:Main.java

public static boolean isExists(String urlString) {
    try {//from ww  w  . j av  a  2s  .c o m
        URL u = new URL(urlString);
        HttpURLConnection huc = (HttpURLConnection) u.openConnection();
        huc.setRequestMethod("GET");
        huc.connect();
        int rc = huc.getResponseCode();
        return (rc == HttpURLConnection.HTTP_OK);
        // Handle response code here...
    } catch (UnknownHostException uhe) {
        // Handle exceptions as necessary
        Log.w("EPub", uhe.getMessage());
    } catch (FileNotFoundException fnfe) {
        // Handle exceptions as necessary
        Log.w("EPub", fnfe.getMessage());
    } catch (Exception e) {
        // Handle exceptions as necessary
        Log.w("EPub", e.getMessage());
    }
    return false;
}

From source file:Main.java

public static void saveThumb(Context context, String thumbName, Bitmap image) {
    if (thumbName == null || thumbName.length() <= 0)
        return;//from  w  ww. j a  v a 2s  .  c  o m

    File pictureFile = getOutputMediaFile(context, thumbName);
    File dir = new File(context.getCacheDir() + "/thumbnails");
    if (dir.exists())//too many caches
    {
        File files[] = dir.listFiles();
        if (files.length > CACHE_LIMIT)
            files[0].deleteOnExit();
    }
    if (pictureFile == null) {
        Log.d(TAG, "Error creating media file, check storage permissions: ");// e.getMessage());
        return;
    }
    try {
        FileOutputStream fos = new FileOutputStream(pictureFile);
        image.compress(Bitmap.CompressFormat.PNG, 90, fos);
        fos.close();
    } catch (FileNotFoundException e) {
        Log.d(TAG, "File not found: " + e.getMessage());
    } catch (IOException e) {
        Log.d(TAG, "Error accessing file: " + e.getMessage());
    }
}

From source file:Main.java

@SuppressWarnings("unused")
private static void saveImage(byte[] data) {
    File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
    if (pictureFile == null) {
        Log.d(TAG, "Error creating media file, check storage permissions");
        return;//from   w  w w.  ja  va2s.  c o  m
    }

    try {
        FileOutputStream fos = new FileOutputStream(pictureFile);
        fos.write(data);
        fos.close();
    } catch (FileNotFoundException e) {
        Log.d(TAG, "File not found: " + e.getMessage());
    } catch (IOException e) {
        Log.d(TAG, "Error accessing file: " + e.getMessage());
    }
}

From source file:com.clustercontrol.winsyslog.WinSyslogConfig.java

public static void init(String confFile) {
    log.debug("init() : propFileName = " + confFile);
    FileInputStream inputStream = null;
    try {// ww w  .  ja va 2  s  .c o  m
        inputStream = new FileInputStream(confFile);
        properties.load(inputStream);
    } catch (FileNotFoundException e) {
        log.error(e.getMessage(), e);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    } finally {
        if (inputStream != null) {
            try {
                inputStream.close();
            } catch (IOException e) {
                log.error(e.getMessage(), e);
            }
        }
    }
}

From source file:Main.java

public static <T> T fromXml(File xmlPath, Class<T> type) {
    BufferedReader reader = null;
    StringBuilder sb = null;//from  ww  w.j  av  a  2  s  .  c om
    try {
        reader = new BufferedReader(new InputStreamReader(new FileInputStream(xmlPath), ENCODING));
        String line = null;
        sb = new StringBuilder();
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
    } catch (FileNotFoundException e) {
        throw new IllegalArgumentException(e.getMessage());
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }
    return fromXml(sb.toString(), type);
}

From source file:client.communication.SocketClient.java

public static void init() {
    BufferedReader buf;//from  www.  j  a  va  2s.  c o  m

    try {
        buf = new BufferedReader(new FileReader("src/ip.txt"));

        serverAddress = buf.readLine();

        //            System.out.println("Address: " + serverAddress);

        buf.close();
    } catch (FileNotFoundException e) {
        System.err.println(e.getMessage());
    } catch (IOException e) {
        System.err.println(e.getMessage());
    }
}