Example usage for java.io File getPath

List of usage examples for java.io File getPath

Introduction

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

Prototype

public String getPath() 

Source Link

Document

Converts this abstract pathname into a pathname string.

Usage

From source file:Main.java

public static long getAvailableExternalMemorySize() {
    if (isExternalMemoryAvailable() == true) {
        File path = Environment.getExternalStorageDirectory();
        StatFs stat = new StatFs(path.getPath());
        long blockSize = 0;
        long availableBlocks = 0;
        blockSize = stat.getBlockSize();
        availableBlocks = stat.getAvailableBlocks();

        return availableBlocks * blockSize;
    } else {//from  w  ww. ja  v  a 2 s  .co  m
        return -1;
    }
}

From source file:Main.java

private static void checkFile(File file) throws IOException {
    boolean exists = file.exists();
    if (exists && !file.isFile()) {
        throw new IOException("File " + file.getPath() + " is actually not a file.");
    }/*from w  ww  . j a  v a 2s.co m*/
}

From source file:com.zilotti.utils.NetworkUtils.java

/**
 * Provides the full path to the hosts file of the current
 * operational system./* ww w  .j av  a2  s.  co m*/
 *  
 * @return
 */
public static File getSystemHostsFilePath() {
    if (SystemUtils.IS_OS_LINUX)
        return new File("/etc/hosts");

    if (SystemUtils.IS_OS_MAC || SystemUtils.IS_OS_MAC_OSX)
        return new File("/private/etc/hosts");

    if (SystemUtils.IS_OS_WINDOWS) {
        // TODO: Implement on Windows environment
        File[] roots = FileSystemView.getFileSystemView().getRoots();
        for (File root : roots)
            System.out.println(root.getPath());

        return new File("c:/Windows/system32/drivers/etc/hosts");
    }

    throw new RuntimeException("Operational System not supported: " + System.getProperty("os.name"));
}

From source file:Main.java

public static Boolean canWrite(File f) {
    if (f.isDirectory()) {
        FileWriter w = null;/* ww w.j  av a  2 s  .c o m*/
        String testFilename = f.getPath() + "/.EASYRPG_WRITE_TEST";
        try {
            w = new FileWriter(testFilename);
            // Permissions are checked on open, but it is Android, better be save
            w.write("Android >.<");
        } catch (IOException e) {
            return false;
        } finally {
            try {
                if (w != null) {
                    w.close();
                }
            } catch (IOException e) {
            }
        }

        File testFile = new File(testFilename);
        if (testFile.exists()) {
            // Does not throw
            testFile.delete();
        }
    } else {
        boolean deleteAfter = f.exists();
        try {
            FileWriter w = new FileWriter(f, true);
            w.close();
        } catch (IOException e) {
            return false;
        }

        if (deleteAfter) {
            f.delete();
        }
    }

    return true;
}

From source file:me.doshou.admin.maintain.editor.web.controller.utils.OnlineEditorUtils.java

public static boolean hasParent(File currentFile, String rootPath) {
    return !currentFile.getPath().equals(rootPath);
}

From source file:naftoreiclag.villagefive.addon.AddonManager.java

public static void reloadAddons() {
    addonCollection.clear();/*ww w . j ava2s  .c o m*/

    File[] pluginRoots = (new File(SAM.ADDON_DIR)).listFiles((FileFilter) DirectoryFileFilter.DIRECTORY);

    // 
    for (File pluginRoot : pluginRoots) {
        System.out.println(pluginRoot);
        String addon_root = pluginRoot.getPath().replace('\\', '/') + "/";

        Globals globals = JsePlatform.standardGlobals();
        globals.set("ADDON_ROOT", addon_root);
        globals.loadfile("lua/globals.lua").call();

        LuaTable data = globals.loadfile(addon_root + "addon.lua").call().checktable();

        LuaAddon addon = new LuaAddon(pluginRoot.getName() + "\\", data);

        addonCollection.put(addon.id, addon);
    }

    for (Map.Entry<String, LuaAddon> pair : addonCollection.entrySet()) {
        LuaAddon addon = pair.getValue();

        System.out.println(addon.id);
        for (LuaEntity entity : addon.entities) {
            System.out.println(entity.parent.id + ":" + entity.id);
            EntityRegistry.register(entity);
        }
    }
}

From source file:IO.Directories.java

/**
 * Return ArrayList<String> filed with the paths of the files in the given
 * folder//from  w w w  .  j  a v  a 2  s . c om
 *
 * @param folder_path path of a folder
 * @return ArrayList<String> filed with the paths of the files in the given
 * folder
 */
private static ArrayList<String> GetFolderFilesPaths(String folderPath) {
    ArrayList<String> filesPaths = new ArrayList<>();
    File directory = new File(folderPath);
    if (directory.exists()) {
        File[] directoryFiles = directory.listFiles();
        for (File file : directoryFiles) {
            filesPaths.add(file.getPath());
        }
    }
    return filesPaths;
}

From source file:Main.java

/**
 * Copy configuration file from assets to data folder.
 *
 * @param file File to copy/*from  w w  w  . j ava 2s  .  com*/
 */
private static void copyAssetToData(File file) {
    try {
        InputStream myInput = mContext.getAssets().open(file.getName());
        String outFileName = file.getPath();
        OutputStream myOutput = new FileOutputStream(outFileName);
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer)) > 0) {
            myOutput.write(buffer, 0, length);
        }
        myOutput.flush();
        myOutput.close();
        myInput.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static String writeBitmap(byte[] data) throws IOException {
    File file = new File(Environment.getExternalStorageDirectory() + "/bookclip/");
    file.mkdir();/*www .jav  a2s . c o m*/
    String bitmapPath = file.getPath() + "/" + System.currentTimeMillis() + ".jpg";
    FileOutputStream outStream = new FileOutputStream(bitmapPath);
    outStream.write(data);
    outStream.close();

    return bitmapPath;
}

From source file:hu.bme.mit.incqueryd.engine.util.EObjectDeserializer.java

public static EObject deserializeFromString(final String model, Set<? extends EPackage> packages)
        throws IOException {
    final File tempFile = EObjectSerializer.createTempFile();
    FileUtils.writeStringToFile(tempFile, model);
    return deserializeFromFile(tempFile.getPath(), packages);
}