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:Main.java

/**
 * DB test/*from w  w w .j a  v a2s.c om*/
 */
public static void runBackup(Context context) {
    File file = context.getDatabasePath("PhotoDeskHiddenFolder.db");
    int size = (int) file.length();

    String path = Environment.getExternalStorageDirectory() + "/PhotoDesk/";
    try {
        byte[] buffer = new byte[size];
        InputStream inputStream = new FileInputStream(file);
        inputStream.read(buffer);
        inputStream.close();

        File outputDBDirectory = new File(path);
        if (!outputDBDirectory.isDirectory())
            outputDBDirectory.mkdir();

        path += "test.db";

        File outputFile = new File(path);
        FileOutputStream outputStream = new FileOutputStream(outputFile);
        outputStream.write(buffer);
        outputStream.flush();
        outputStream.close();

    } catch (Exception e) {
    }
}

From source file:Main.java

public static String readFile(Context context, String name) throws IOException {
    File file = context.getFileStreamPath(name);
    InputStream is = new FileInputStream(file);

    byte b[] = new byte[(int) file.length()];

    is.read(b);/*from   ww  w .j ava2s .  c  om*/
    is.close();

    String string = new String(b);

    return string;
}

From source file:com.tek271.reverseProxy.utils.FileTools.java

public static long size(File file) {
    if (file == null) {
        return 0;
    }//w  ww. ja  va2  s . c  o m
    return file.length();
}

From source file:Util.java

public static byte[] readFile(File file) throws IOException {
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
    int bytes = (int) file.length();
    byte[] buffer = new byte[bytes];

    int readBytes = bis.read(buffer);
    bis.close();//from   w w  w  .  ja v  a 2  s  .c  o  m
    return buffer;
}

From source file:net.dfs.user.test.Store.java

public static void store(String file) throws UnknownHostException {
    File f = new File(file);
    FILE_SIZE = f.length();

    fileNameAnalyzer(file);//from   www  .j a v a2 s  .c  o m

    StorageConnectionHandler storageHandler = (StorageConnectionHandler) context.getBean("storageHandler");
    String serverName = storageHandler.storeFile(FILE_SIZE, fileName, extention,
            InetAddress.getLocalHost().getHostAddress());

    Store.serverName(serverName);
    log.debug("The File " + fileName + extention + " With " + FILE_SIZE + " size send to the Server");

}

From source file:Main.java

public static boolean isPhotoReallyCropped(Uri uri) {
    File file = new File(uri.getPath());
    long length = file.length();
    return length > 0;
}

From source file:Main.java

public static String setImBin(String fName) {
    FileInputStream fileInputStream = null;

    File file = new File(Environment.getExternalStorageDirectory().getPath(), "Pictures/" + fName);

    byte[] bFile = new byte[(int) file.length()];

    try {//from   w  ww  . java 2s .co m
        fileInputStream = new FileInputStream(file);
        fileInputStream.read(bFile);
        fileInputStream.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
    return Base64.encodeToString(bFile, Base64.DEFAULT);
}

From source file:Main.java

public static String encodeToFile(File file) {
    try {//from  w w w  . j  a va  2  s.  c om
        FileInputStream inputFile = new FileInputStream(file);
        byte[] buffer = new byte[(int) file.length()];
        inputFile.read(buffer);
        inputFile.close();
        return Base64.encodeToString(buffer, Base64.NO_WRAP);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static byte[] readBytesFromFile(File file) {
    if (file != null && file.exists() && file.isFile()) {
        int filelength = (int) file.length();
        byte[] filecontent = new byte[filelength];
        try {/*  w w w . ja va  2s .  c  o m*/
            FileInputStream in = new FileInputStream(file);
            in.read(filecontent);
            in.close();

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

From source file:Main.java

public static boolean checkIfDllInstalled(Context context) {
    boolean isInstalled = false;
    try {//from   ww w .j a v  a 2  s  . co  m
        InputStream inputStream = context.getAssets().open("Disdll.dll");
        File file = context.getFileStreamPath("Disdll.dll");
        if (file != null) {
            if (file.length() == inputStream.available()) {
                isInstalled = true;
            }
        }
        inputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return isInstalled;
}