Example usage for java.io File separator

List of usage examples for java.io File separator

Introduction

In this page you can find the example usage for java.io File separator.

Prototype

String separator

To view the source code for java.io File separator.

Click Source Link

Document

The system-dependent default name-separator character, represented as a string for convenience.

Usage

From source file:Main.java

public static File getDiskCacheDir(Context context, String uniqueName) {
    String cachePath;// w  w w .j ava  2 s .c  o m
    if ((Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())
            || !Environment.isExternalStorageRemovable()) && context.getExternalCacheDir() != null
            && !TextUtils.isEmpty(context.getExternalCacheDir().getPath())) {
        cachePath = context.getExternalCacheDir().getPath();
    } else {
        cachePath = context.getCacheDir().getPath();
    }
    return new File(cachePath + File.separator + uniqueName);
}

From source file:Main.java

public static String zip(String filename) throws IOException {
    BufferedInputStream origin = null;
    Integer BUFFER_SIZE = 20480;/*from  w ww.  j  av a2 s .com*/

    if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {

        File flockedFilesFolder = new File(
                Environment.getExternalStorageDirectory() + File.separator + "FlockLoad");
        System.out.println("FlockedFileDir: " + flockedFilesFolder);
        String uncompressedFile = flockedFilesFolder.toString() + "/" + filename;
        String compressedFile = flockedFilesFolder.toString() + "/" + "flockZip.zip";
        ZipOutputStream out = new ZipOutputStream(
                new BufferedOutputStream(new FileOutputStream(compressedFile)));
        out.setLevel(9);
        try {
            byte data[] = new byte[BUFFER_SIZE];
            FileInputStream fi = new FileInputStream(uncompressedFile);
            System.out.println("Filename: " + uncompressedFile);
            System.out.println("Zipfile: " + compressedFile);
            origin = new BufferedInputStream(fi, BUFFER_SIZE);
            try {
                ZipEntry entry = new ZipEntry(
                        uncompressedFile.substring(uncompressedFile.lastIndexOf("/") + 1));
                out.putNextEntry(entry);
                int count;
                while ((count = origin.read(data, 0, BUFFER_SIZE)) != -1) {
                    out.write(data, 0, count);
                }
            } finally {
                origin.close();
            }
        } finally {
            out.close();
        }
        return "flockZip.zip";
    }
    return null;
}

From source file:Main.java

private static File getOutputMediaFile(Context context, String thumbName) {
    File file = new File(context.getCacheDir() + "/thumbnails/" + thumbName + ".png");
    if (!file.exists()) {
        File mediaStorageDir = new File(context.getCacheDir() + "/thumbnails");

        // Create the storage directory if it does not exist
        if (!mediaStorageDir.exists()) {
            if (!mediaStorageDir.mkdirs()) {
                return null;
            }//from  ww w. ja  v a2  s  .c om
        }
        // Create a media file name
        String mImageName = thumbName + ".png";
        File mediaFile = new File(mediaStorageDir.getPath() + File.separator + mImageName);
        return mediaFile;
    } else {
        return file;
    }
}

From source file:Main.java

public static void copyFiles(String sourcePath, String targetPath) throws IOException {
    File srcDir = new File(sourcePath);
    File[] files = srcDir.listFiles();
    FileChannel in = null;/* ww  w. ja  v  a 2  s.  c  om*/
    FileChannel out = null;
    for (File file : files) {
        try {
            in = new FileInputStream(file).getChannel();
            File outDir = new File(targetPath);
            if (!outDir.exists()) {
                outDir.mkdirs();
            }
            File outFile = new File(targetPath + File.separator + file.getName());
            out = new FileOutputStream(outFile).getChannel();
            in.transferTo(0, in.size(), out);
        } finally {
            if (in != null)
                in.close();
            if (out != null)
                out.close();
        }
    }
}

From source file:com.orchestra.portale.utils.InsertUtils.java

public static String delimg(HttpServletRequest request, String id, String nameimg) {
    String esito = "";
    HttpSession session = request.getSession();
    ServletContext sc = session.getServletContext();
    File dir = new File(sc.getRealPath("/") + "dist" + File.separator + "poi" + File.separator + "img"
            + File.separator + id);

    File img = new File(dir.getAbsolutePath() + File.separator + nameimg);
    if (img.delete())
        esito = "OK";
    else// ww  w.j  a  v a  2s.c  o  m
        esito = "ERRORE";

    return esito;
}

From source file:Main.java

public static File getImageSavePath() {
    final File folder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator
            + "MGJ-IM" + File.separator + "images");
    if (!folder.exists()) {
        folder.mkdirs();/*from  w w  w .j  av  a  2 s. c o m*/
    }
    return folder;
}

From source file:Main.java

/**
 * Reads in model 83 points and returns a double array float containing the
 * coordinates x & y.//from  www . j  a  va 2  s .co m
 */
public static float[][][] readBinSFSV(String dir, String fileName) {
    float[][][] array3D = new float[60][83][3];
    float x;
    File sdLien = Environment.getExternalStorageDirectory();
    File inFile = new File(sdLien + File.separator + dir + File.separator + fileName);
    Log.d(TAG, "path of file : " + inFile);
    if (!inFile.exists()) {
        throw new RuntimeException("File doesn't exist");
    }
    DataInputStream in = null;
    try {
        in = new DataInputStream(new FileInputStream(inFile));
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    try {
        for (int k = 0; k < 3; k++) {
            for (int j = 0; j < 83; j++) {
                for (int i = 0; i < 60; i++) {
                    x = in.readFloat();
                    array3D[i][j][k] = x;
                }
            }
        }
    } catch (EOFException e) {
        try {
            Log.d(TAG, "close");
            in.close();
        } catch (IOException e1) {
            e1.printStackTrace();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (in != null) {
            try { //free ressources
                Log.d(TAG, "close");
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return array3D;
}

From source file:Main.java

public static boolean copyAssetFile(Context context, String originFileName, String destFilePath,
        String destFileName) {//w w w .j a  v  a  2s .co m
    InputStream is = null;
    BufferedOutputStream bos = null;
    try {
        is = context.getAssets().open(originFileName);
        File destPathFile = new File(destFilePath);
        if (!destPathFile.exists()) {
            destPathFile.mkdirs();
        }

        File destFile = new File(destFilePath + File.separator + destFileName);
        if (!destFile.exists()) {
            destFile.createNewFile();
        }

        FileOutputStream fos = new FileOutputStream(destFile);
        bos = new BufferedOutputStream(fos);

        byte[] buffer = new byte[256];
        int length = 0;
        while ((length = is.read(buffer)) > 0) {
            bos.write(buffer, 0, length);
        }
        bos.flush();

        return true;
    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        if (null != is) {
            try {
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        if (null != bos) {
            try {
                bos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    return false;
}

From source file:Main.java

public static Bitmap getBitmap(String fileName) {
    Bitmap bitmap = getBitmapFromCache(fileName);
    if (bitmap != null) {
        return bitmap;
    }/*  www  . j ava 2  s  . co m*/

    // modify the file attribute
    String filePath = getStorageDirectory() + File.separator + fileName;
    File file = new File(filePath);
    long time = new Date().getTime();
    file.setLastModified(time);
    return BitmapFactory.decodeFile(filePath);
}

From source file:Main.java

public static String getFileDir(String filePath) {
    return filePath.substring(0, filePath.lastIndexOf(File.separator));
}