Code example for FileChannel

Methods: truncate

0
    private long truncateFile(String filename, long size) throws FileNotFoundException, IOException {
        RandomAccessFile raf = new RandomAccessFile(filename, "rw");
 
        if (raf.length() >= size) {
               FileChannel channel = raf.getChannel();
               channel.truncate(size);
               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 {
        if (path.startsWith("content")) {