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

/**
 * get the space is left over on sdcard/*www.j a va 2  s  .  c  o  m*/
 */
public static long getRealSizeOnSdcard() {
    File path = new File(Environment.getExternalStorageDirectory().getAbsolutePath());
    StatFs stat = new StatFs(path.getPath());
    long blockSize = stat.getBlockSize();
    long availableBlocks = stat.getAvailableBlocks();
    return availableBlocks * blockSize;
}

From source file:Main.java

public static File createPhotoFile(File pictureFileDir, long captureTime) {
    String photoFile = "Picture_" + captureTime + ".jpg";
    String filename = pictureFileDir.getPath() + File.separator + photoFile;
    return new File(filename);
}

From source file:Main.java

public static String getSaveImgPath(Context context, String url) {
    //      String fileName = url.substring(url.lastIndexOf("/") + 1);
    File mediaStorageDir = new File(context.getExternalFilesDir(Environment.DIRECTORY_RINGTONES), SaveImg);

    return mediaStorageDir.getPath();
    //            + File.separator + fileName;
}

From source file:Main.java

private static void getFiles(File aRootDir, Boolean aIsGetRelativePath, File aDirPath, boolean aIsContainSubDir,
        FilenameFilter aFilenameFilter, Collection<String> aOutList) {
    if (aOutList == null) {
        aOutList = new ArrayList<String>();
    }//from   w  w  w .  j  a  v  a 2 s  .  co  m

    File[] files = aDirPath.listFiles(aFilenameFilter);

    for (int i = 0; i < files.length; i++) {
        File f = files[i];
        if (f.isFile()) {
            String strPath = f.getPath();
            if (aRootDir != null && aIsGetRelativePath) {
                strPath = strPath.substring(aRootDir.getPath().length());
            }
            aOutList.add(strPath);
            if (!aIsContainSubDir)
                break;
        } else if (f.isDirectory() && f.getPath().indexOf("/.") == -1)
            getFiles(aRootDir, aIsGetRelativePath, f, aIsContainSubDir, aFilenameFilter, aOutList);
    }
}

From source file:com.thoughtworks.go.util.TestUtils.java

public static TypeSafeMatcher<File> isSamePath(final File fileToMatch) {
    return new TypeSafeMatcher<File>() {
        public String actual;
        public String expected;

        public boolean matchesSafely(File o) {
            actual = o.getPath();
            expected = fileToMatch.getPath();
            return actual.equals(expected);
        }//  w w w. jav a 2s.  c  o m

        public void describeTo(Description description) {
            description.appendText(
                    "The actual path: [" + actual + "] does not match the expected path [" + expected + "]");
        }
    };
}

From source file:ImageUtil.java

/**
 * get image orientation type//w w w .j  a  v  a 2  s  .c o  m
 * @param imageFile
 * @return 0:Landscape, 1:Portrait
 */
public static int getOrientation(File imageFile) {
    int result = 0;
    ImageIcon image = new ImageIcon(imageFile.getPath());
    if (image.getIconWidth() > image.getIconHeight()) {
        result = 0;
    } else {
        result = 1;
    }
    image = null;
    return result;
}

From source file:com.mirth.connect.util.AttachmentUtil.java

public static void writeToFile(String filePath, Attachment attachment, boolean binary) throws IOException {
    File file = new File(filePath);
    if (!file.canWrite()) {
        String dirName = file.getPath();
        int i = dirName.lastIndexOf(File.separator);
        if (i > -1) {
            dirName = dirName.substring(0, i);
            File dir = new File(dirName);
            dir.mkdirs();//from  w w w  .  j  a  v a 2  s.c o m
        }
        file.createNewFile();
    }

    if (attachment != null && StringUtils.isNotEmpty(filePath)) {
        FileUtils.writeByteArrayToFile(file,
                binary ? Base64Util.decodeBase64(attachment.getContent()) : attachment.getContent());
    }
}

From source file:com.mobius.software.mqtt.performance.runner.util.FileUtil.java

public static File readFile(String filename) throws URISyntaxException, IllegalArgumentException {
    String path = ScenarioRunner.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
    File file = new File(path).getParentFile();
    file = new File(file.getPath() + File.separator + filename);
    if (!file.exists())
        throw new IllegalArgumentException("file not found: " + filename);
    return file;//from w w  w .  j  a  v a  2s.  c  o m
}

From source file:Main.java

public static String getApkFilePackage(Context context, File apkFile) {
    PackageManager pm = context.getPackageManager();
    PackageInfo info = pm.getPackageArchiveInfo(apkFile.getPath(), PackageManager.GET_ACTIVITIES);
    if (info != null) {
        return info.applicationInfo.packageName;
    }//from  w  ww  .  ja  v  a 2s .  com
    return null;
}

From source file:com.machinelinking.util.FileUtil.java

public static InputStream openDecompressedInputStream(File file) throws IOException {
    final String ext = getExtension(file.getPath());
    return openDecompressedInputStream(new FileInputStream(file), ext);
}