Example usage for java.io IOException toString

List of usage examples for java.io IOException toString

Introduction

In this page you can find the example usage for java.io IOException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:Main.java

public static void writeToFile(String path, String data) {
    try {//w  w w.j ava  2 s.co m
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(new FileOutputStream(path));
        outputStreamWriter.write(data);
        outputStreamWriter.close();
    } catch (IOException e) {
        Log.e("Exception", "File write failed: " + e.toString());
    }
}

From source file:Main.java

private static void closeInputStream(InputStream in) {
    if (null != in) {
        try {//from w ww.ja  va 2 s  .  com
            in.close();
        } catch (IOException e) {
            Log.v("BitMapUtil", "closeInputStream==" + e.toString());
        }
    }
}

From source file:Main.java

private static void closeInputStream(InputStream in) {
    if (null != in) {
        try {/*from  www  .  j  a  va2s  . c  o m*/
            in.close();
        } catch (IOException e) {
            Log.e("BitMapUtil", "closeInputStream==" + e.toString());
        }
    }
}

From source file:Main.java

public static Bitmap loadBitmapAsset(Context context, String asset) {
    InputStream is = null;//  w  w  w  . j  a v a  2  s  .com
    Bitmap bitmap = null;
    try {
        is = context.getAssets().open(asset);
        if (is != null) {
            bitmap = BitmapFactory.decodeStream(is);
        }
    } catch (IOException e) {
        Log.e(TAG, e.toString());
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                Log.e(TAG, "Cannot close InputStream: ", e);
            }
        }
    }
    return bitmap;
}

From source file:Main.java

public static File writeLog(String root, String filename) {
    StringBuilder log = new StringBuilder();
    try {/*ww  w.j  a va 2  s . c o  m*/
        Process process = Runtime.getRuntime().exec("logcat -d");
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        String line;
        while ((line = bufferedReader.readLine()) != null) {
            log.append(line).append("\n");
        }
    } catch (IOException e) {
        log.append(e.toString());
    }

    File file = new File(root, filename);

    try {
        FileOutputStream fOut = new FileOutputStream(file);
        OutputStreamWriter osw = new OutputStreamWriter(fOut);

        // Write the string to the file
        osw.write(log.toString());
        osw.flush();
        osw.close();

    } catch (Exception e) {
        Log.e(TAG, String.format("Failed to write log to [%s]", file), e);
    }
    return file;
}

From source file:Main.java

private static void createNoMediaFile(File file) {
    try {//  w w w .  j a v  a  2 s .  c o m
        File noMediaFile = new File(file, NO_MEDIA_FILE);

        if (!noMediaFile.exists()) {
            noMediaFile.createNewFile();
        }
    } catch (IOException e) {
        Log.w(TAG, e.toString());
    }
}

From source file:Main.java

public static String locationToAddress(Location loc, Context context) {
    try {// w  w w.j a  v  a2  s  .co m
        double latitude, longitude;
        String addressText = "";
        geocoder = new Geocoder(context);
        latitude = loc.getLatitude();
        longitude = loc.getLongitude();
        List<Address> list = geocoder.getFromLocation(latitude, longitude, 1);

        if (list != null && list.size() > 0) {
            Address address = list.get(0);
            addressText = String.format("%s, %s, %s",
                    address.getMaxAddressLineIndex() > 0 ? address.getAddressLine(0) : "",
                    address.getLocality(), address.getCountryName());
        }

        return addressText;
    } catch (IOException e) {
        Log.e(LogDavid, "ERROR:" + e.toString());
        return "";
    }
}

From source file:Main.java

/**
 * Reads test json//from  w w w .j  ava2 s .c  om
 *
 * @param filename
 * @return
 */
public static String readJSON(String filename) {
    try {
        FileInputStream fileInputStream = new FileInputStream(new File(filename));
        InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream);
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

        String readData = "";
        StringBuffer stringBuffer = new StringBuffer();
        while ((readData = bufferedReader.readLine()) != null) {
            stringBuffer.append(readData);
        }
        return stringBuffer.toString();

    } catch (IOException e) {
        e.printStackTrace();
        return e.toString();
    }
}

From source file:Main.java

public static String getAbsPath(File file) {
    String path = null;//  www . j  a  v  a2 s.c  o m
    try {
        path = file.getCanonicalPath();
    } catch (IOException e) {
        path = file.getAbsolutePath();
        Log.i("[explorer():]", e.toString());
    }

    return path;
}

From source file:Main.java

public static void copyFileToDir(File sourceFile, File destFile) {
    InputStream inStream = null;/*from   w  w w  . j a  v a2 s.co  m*/
    OutputStream outStream = null;

    try {

        inStream = new FileInputStream(sourceFile);
        outStream = new FileOutputStream(destFile);

        byte[] buffer = new byte[1024];

        int length;

        // copy the file content in bytes
        while ((length = inStream.read(buffer)) > 0) {

            outStream.write(buffer, 0, length);

        }

        Log.d(TAG, "File copied: " + destFile);

    } catch (IOException e) {
        Log.w(TAG, e.toString());
    } finally {
        if (inStream != null) {
            try {
                inStream.close();
            } catch (IOException e) {
                Log.d(TAG, e.toString());
            }
        }

        if (outStream != null) {
            try {
                outStream.close();
            } catch (IOException e) {
                Log.d(TAG, e.toString());
            }
        }
    }
}