Example usage for java.io File length

List of usage examples for java.io File length

Introduction

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

Prototype

public long length() 

Source Link

Document

Returns the length of the file denoted by this abstract pathname.

Usage

From source file:shootersubdownloader.Shootersubdownloader.java

static String computefilehash(File f) throws Exception {
    if (!f.exists() || f.length() < 8 * 1024) {
        return null;
    }//from   w  ww .ja va2 s.c  o  m
    long l = f.length();
    long[] offset = new long[4];
    offset[3] = l - 8 * 1024;
    offset[2] = l / 3;
    offset[1] = l / 3 * 2;
    offset[0] = 4 * 1024;
    byte[] bBuf = new byte[1024 * 4];
    RandomAccessFile raf = new RandomAccessFile(f, "r");
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < 4; i++) {
        raf.seek(offset[i]);
        int readlen = raf.read(bBuf, 0, 4 * 1024);
        String md5 = md5(bBuf);
        if (sb.length() != 0) {
            sb.append("%3B");
        }
        sb.append(md5);
    }
    raf.close();
    return sb.toString();
}

From source file:Main.java

public static String isFileDownloaded(String filename, int contentlen) {

    Log.i(tag, "filename:" + filename);
    Log.i(tag, "len:" + contentlen);
    File f = new File(filename);

    if (!f.exists()) {
        return "init";
    }/*from w  w w  .j a v a  2 s.c  om*/
    Log.i(tag, "f.length():" + f.length());

    if (f.length() < contentlen) {
        return "downloading";
    }

    if (f.length() == contentlen) {
        return "finished";
    }

    return "error";

}

From source file:com.edduarte.argus.util.Constants.java

public static long folderSize(File directory) {
    long length = 0;
    File[] subFiles = directory.listFiles();
    if (subFiles != null) {
        for (File f : subFiles) {
            length += f.isFile() ? f.length() : folderSize(f);
        }/*  ww w.  j a  v  a 2 s  .  co  m*/
    }
    return length;
}

From source file:com.github.megatronking.svg.cli.Main.java

private static void svg2vectorForDirectory(File inputDir, File outputDir, int width, int height) {
    File[] childFiles = inputDir.listFiles();
    if (childFiles != null) {
        for (File childFile : childFiles) {
            if (childFile.isFile() && childFile.length() > 0) {
                svg2vectorForFile(childFile,
                        new File(outputDir, FileUtils.noExtensionLastName(childFile) + ".xml"), width, height);
            }/*ww  w.j av  a2  s.co  m*/
        }
    }
}

From source file:Main.java

public static long getFolderSize(File file) throws Exception {
    long size = 0;
    File[] fileList = file.listFiles();
    for (File f : fileList) {
        if (f.isDirectory()) {
            size += getFolderSize(f);//www  .jav  a2 s.c  om
        } else {
            size += f.length();
        }
    }
    return size;
}

From source file:Main.java

public static byte[] readBytesFromFile(String path) {
    if (path == null || path.trim().length() == 0) {
        return null;
    }//from  www  . j  av a 2  s.c om

    File file = new File(path);

    if (file.exists() && file.isFile()) {
        int filelength = (int) file.length();
        byte[] filecontent = new byte[filelength];
        try {
            FileInputStream in = new FileInputStream(file);
            in.read(filecontent);
            in.close();

        } catch (IOException e) {
            Log.v(TAG, "read file is error");
            return null;
        }
        return filecontent;
    }
    return null;
}

From source file:Main.java

/**
 * //from ww w .  jav a 2s  .  c  o m
 * @param data
 */
private static String readFromFile(String filename) {
    File file = new File(filename);
    byte b[] = null;
    try {
        if (file.exists()) {
            b = new byte[(int) file.length()];
            InputStream fi = new FileInputStream(file);
            fi.read(b);
            fi.close();
        }
    } catch (Exception e) {
        return null;
    }

    if (null != b) {
        return new String(b);
    }
    return null;
}

From source file:com.vaadin.testbench.testutils.ImageLoader.java

public static byte[] loadImageBytes(String folder, String filename) throws IOException {
    File imgFile = getImageFile(folder, filename);
    assertTrue(imgFile.exists());/*from w  w  w.  j  a  v a  2s . co  m*/

    byte[] bytes = new byte[(int) imgFile.length()];
    new DataInputStream(new FileInputStream(imgFile)).readFully(bytes);
    return bytes;
}

From source file:Main.java

public static boolean isFilesReady(Context context) {
    File hpDir = getSDDir(context);
    if (!hpDir.exists() || !hpDir.isDirectory()) {
        return false;
    }//w  w w .  j a  va 2 s .c om
    File hp = new File(hpDir, "hp48");
    File rom = new File(hpDir, "rom");
    File ram = new File(hpDir, "ram");
    return hp.exists() && hp.length() > 0 && rom.exists() && rom.length() > 0 && ram.exists()
            && ram.length() > 0;
}

From source file:Main.java

private static long getFileSize(File file) {
    long size = 0;
    for (File subFile : file.listFiles()) {
        if (subFile.isDirectory()) {
            size += getFileSize(subFile);
        } else {/*from  w  w  w . j a  v a2s .co m*/
            size += subFile.length();
        }
    }
    return size;
}