Code example for FileChannel

Methods: truncate

    private long truncateFile(String filename, long size) throws FileNotFoundException, IOException {
        RandomAccessFile raf = new RandomAccessFile(filename, "rw");
        if (raf.length() >= size) {
               FileChannel channel = raf.getChannel();
               return size;
        return raf.length();
     * Get an input stream based on file path or content:// uri 
     * @param path 
     * @return an input stream 
     * @throws FileNotFoundException 
    private InputStream getPathFromUri(String path) throws FileNotFoundException {
Connect your IDE to all the code out there  Get Codota for Java