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:DBMS.UpdateFileUpload.java

public static boolean processFile(String path, FileItemStream item, int id) {
    try {//from w w  w .  j a  va 2  s. c o  m
        String check = item.getName();
        if (check.endsWith(".jpg") || check.endsWith(".JPG")) {
            String imstring = "images/" + Integer.toString(id);
            File f = new File(path + File.separator + imstring);
            if (!f.exists())
                f.mkdir();
            File savedFile = new File(f.getAbsolutePath() + File.separator + item.getName());
            FileOutputStream fos = new FileOutputStream(savedFile);
            InputStream is = item.openStream();
            int x = 0;
            byte[] b = new byte[1024];
            while ((x = is.read(b)) != -1) {
                fos.write(b, 0, x);
            }
            fos.flush();
            fos.close();
            String dbimage = imstring + "/a.jpg";
            //dc.enterImage(dbimage);
            //im =dbimage;
            //System.out.println("Resizing!");
            //Resize rz = new Resize();
            //rz.resize(dbimage);
            BufferedImage originalImage = ImageIO.read(savedFile);
            int type = originalImage.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : originalImage.getType();
            BufferedImage resizeImageJpg = resizeImage(originalImage, type);
            ImageIO.write(resizeImageJpg, "jpg", savedFile);
            File rFile = new File(f.getAbsolutePath() + "/a.jpg");
            savedFile.renameTo(rFile);
            ProfileEditDB dc = new ProfileEditDB();
            dc.enterImage(id, dbimage);
            System.out.println("Link Entered to Database!");
            return true;
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

From source file:Main.java

public static String createDirInHome(Context context, final String subDir)
        throws IOException, InterruptedException {
    File tmpFile = checkAndCreateDir(context.getApplicationInfo().dataDir + File.separator + subDir);
    return tmpFile.getAbsolutePath();
}

From source file:Main.java

/**
 * Remove file information from a filename returning only its path component
 * /*from ww  w  .  j  a va  2  s .  c o  m*/
 * @param filename
 *            The filename
 * @return The path information
        
 */
public static String pathComponent(String filename) {
    int i = filename.lastIndexOf(File.separator);
    return (i > -1) ? filename.substring(0, i) : filename;
}

From source file:Main.java

public static String getElementTypeFile(String rootFolder, String namespace, String elementTypeId) {
    return getElementTypeFolder(rootFolder, namespace, elementTypeId) + File.separator + ELEMENT_TYPE_FILE_NAME;
}

From source file:Main.java

public static void copyAssetFile(AssetManager am, String assetName, File destBaseDir, boolean overwrite)
        throws IOException {
    File destFile = new File(destBaseDir.getAbsolutePath().concat(File.separator).concat(assetName));

    if (destFile.exists() && !overwrite)
        return;/*from ww w.  j  a  va  2  s .com*/

    if (overwrite) {
        destFile.delete();
    }
    destFile.getParentFile().mkdirs();

    InputStream is = null;
    OutputStream os = null;

    try {
        byte[] buff = new byte[4096];
        is = am.open(assetName, AssetManager.ACCESS_STREAMING);
        os = new FileOutputStream(destFile);

        while (true) {
            int nread = is.read(buff);
            if (nread <= 0)
                break;
            os.write(buff, 0, nread);
        }
    } finally {
        closeQuietly(is);
        closeQuietly(os);
    }
}

From source file:Main.java

/**
 * Remove path information from a filename returning only its file component
 * //from  w  w w.  jav  a2 s  . c o  m
 * @param filename
 *            The filename
 * @return The filename sans path information
        
 */
public static String fileComponent(String filename) {
    int i = filename.lastIndexOf(File.separator);
    return (i > -1) ? filename.substring(i + 1) : filename;
}

From source file:Main.java

public static File getOutputMediaFile(int type, Context c) {
    File mediaStorageDir = new File(c.getApplicationContext().getExternalFilesDir(null).getAbsolutePath());
    // Create the storage directory if it does not exist
    if (!mediaStorageDir.exists()) {
        if (!mediaStorageDir.mkdirs()) {
            Log.d("MyCameraApp", "failed to create directory");
            return null;
        }/* w ww . j av  a 2 s .c om*/
    }

    // Create a media file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    File mediaFile;
    if (type == MEDIA_TYPE_IMAGE) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg");
    } else if (type == MEDIA_TYPE_AUDIO) {
        mediaFile = new File(mediaStorageDir.getPath() + File.separator + "VID_" + timeStamp + ".3gp");
    } else {
        return null;
    }

    return mediaFile;
}

From source file:Main.java

/**
 * Given a byte array of content, writes it to a temporary file and then
 * returns the path to it as a URL//www. j a v a2  s  . c o m
 * @param contents The content of the file
 * @param type The file extension to use
 * @throws IOException if an error occurs
 */
public static URL stringToTempFile(byte[] contents, String type) throws IOException {

    // Make sure we have a temp directory
    checkForTempDirectory();

    // Generate a random file name and keep doing it until we get a unique one
    File f = null;
    String fName = null;
    do {
        fName = tempDirectory + File.separator + ((int) (Math.random() * 10000000)) + "." + type;
        f = new File(fName);
    } while (f.exists());

    System.out.println("TEMP: Creating temp file " + fName);
    FileOutputStream out = new FileOutputStream(f);
    out.write(contents);
    out.close();

    // Remember this file for later deletion
    tempFileList.add(fName);

    return new URL("file://" + fName);
}

From source file:Main.java

public static String getTablesInitializationCompleteMarkerFile(String appName) {
    String result = getDataFolder(appName) + File.separator + ODK_TABLES_INIT_FILENAME;
    return result;
}

From source file:Main.java

public static File createFile(Activity activity, String name, boolean isThumbnail) {
    // To be safe, you should check that the SDCard is mounted
    // using Environment.getExternalStorageState() before doing this.
    String subDir;/*w  ww . j  av  a 2 s  .c o  m*/
    String fileType;
    if (isThumbnail) {
        subDir = "/thumbnails";
        fileType = "thumbnail_";
    } else {
        subDir = "/backgrounds";
        fileType = "background_";
    }
    File storageDir = new File(Environment.getExternalStorageDirectory() + "/Android/data/"
            + activity.getApplicationContext().getPackageName() + subDir);
    // Create the storage directory if it does not exist
    if (!storageDir.exists()) {
        if (!storageDir.mkdirs()) {
            return null;
        }
    }
    File thumbnailFile;
    String thumbnailName = fileType + name;
    thumbnailFile = new File(storageDir.getPath() + File.separator + thumbnailName);
    return thumbnailFile;
}