Example usage for java.io FileNotFoundException printStackTrace

List of usage examples for java.io FileNotFoundException printStackTrace

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:Main.java

/**
 * Read details from a file//from w w w  .  j  av a 2s  .co  m
 * @param full_file_name
 * @return
 */
public static String readFile(String full_file_name, Context context) {
    FileInputStream fis = null;
    try {
        fis = context.openFileInput(full_file_name);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    InputStreamReader isr = new InputStreamReader(fis);
    BufferedReader bufferedReader = new BufferedReader(isr);
    StringBuilder sb = new StringBuilder();
    String line;

    try {
        while ((line = bufferedReader.readLine()) != null) {
            sb.append(line);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    // convert stringbuilder to string and split the whole file into multiple people
    return sb.toString();
}

From source file:Main.java

public static void savePic2SD(Bitmap bitmap, String path, String folder) {

    boolean sdCardExist = Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);
    if (sdCardExist) {
        File fileDir = new File(folder);
        if (!fileDir.exists()) {
            fileDir.mkdir();//from   w  ww .  ja v a 2  s  .  com
        }
    }

    File file = new File(path);
    try {
        FileOutputStream out = new FileOutputStream(file);

        if (bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out)) {
            out.flush();
            out.close();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:Main.java

public static String getCurrentProject() {
    try {/*from w w w .ja va 2s.c  o m*/
        String value = "";
        Properties properties = new Properties();
        FileInputStream inputFile = new FileInputStream(System.getProperty("user.dir") + "/system.properties");
        properties.load(inputFile);
        inputFile.close();

        if (properties.containsKey("ProjectPath")) {
            value = properties.getProperty("ProjectPath");
            String resultName = new String(value.getBytes("ISO-8859-1"), "gbk");
            return resultName;
        } else
            return value;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return "";
    } catch (IOException e) {
        e.printStackTrace();
        return "";
    } catch (Exception ex) {
        ex.printStackTrace();
        return "";
    }
}

From source file:Main.java

public static File bitmapToFile(Context context, Bitmap bitmap) {
    File outputFile = getTempFile(context);
    FileOutputStream fos = null;/*from  w w w .java2 s.c o m*/
    try {
        fos = new FileOutputStream(outputFile);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
        fos.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    if (!bitmap.isRecycled()) {
        bitmap.recycle();
    }

    return outputFile;
}

From source file:Main.java

public static void copyfile(File src, File dec) {
    try {//ww  w  .j  av  a2s .co  m
        if (src == null || dec == null) {
            return;
        }

        InputStream in = new FileInputStream(src);
        OutputStream out = new FileOutputStream(dec);

        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        in.close();
        out.close();
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void writeStreamToFile(InputStream is, File file) {
    FileOutputStream fos = null;/*ww  w  . j a  v a2s  .  c  o m*/
    try {
        fos = new FileOutputStream(file);
        byte[] buffer = new byte[4096];
        int length = 0;
        while ((length = is.read(buffer)) != -1) {
            fos.write(buffer, 0, length);
            fos.flush();
        }
        Log.d("tg", "FileUtils writeStreamToFile successed...");
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:Main.java

public static String read(Context context, String fileName) {
    try {//  w w w  .  ja  va2s . c o  m
        FileInputStream in = context.openFileInput(fileName);
        return readInStream(in);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return "";
}

From source file:Main.java

public static Object deserializeObject(File file) {
    Object data = null;/*from  w ww  .java2  s  .  co  m*/
    try {
        FileInputStream os = new FileInputStream(file);
        XMLDecoder decoder = new XMLDecoder(os);
        data = decoder.readObject();
        decoder.close();
    } catch (FileNotFoundException f) {
        data = null;
        f.printStackTrace();
    }
    return data;
}

From source file:Main.java

public static String file2String(File file) {
    FileInputStream fis = null;//from ww w  . j  ava 2s  .  c  o m
    ByteArrayOutputStream baos = null;
    try {
        fis = new FileInputStream(file);
        baos = new ByteArrayOutputStream();
        int i;
        while ((i = fis.read()) != -1) {
            baos.write(i);
        }
        String str = baos.toString();
        return str;
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    } finally {
        try {
            if (fis != null)
                fis.close();
            if (baos != null)
                baos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:Main.java

public static Document stringToDocument(final String source) {
    String tmp = source.trim();/*w w  w .java 2s  .c  o  m*/
    if (!tmp.startsWith("<?xml")) {
        tmp = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + tmp;
    }
    String encode = "utf-8";
    Pattern p = Pattern.compile("<?.*encoding=\"([^ ]*)\".*?>");
    Matcher m = p.matcher(tmp);
    if (m.find()) {
        encode = m.group(1);
    }
    try {
        return DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(new ByteArrayInputStream(tmp.getBytes(encode)));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (SAXException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ParserConfigurationException e) {
        e.printStackTrace();
    }
    return null;
}