Code example for FileChannel

Methods: truncate

0
 
        RandomAccessFile raf = new RandomAccessFile(filename, "rw");
        try { 
            if (raf.length() >= size) {
                FileChannel channel = raf.getChannel();
                channel.truncate(size);
                return size;
            } 
     
            return raf.length();
        } finally { 
            raf.close();
        } 
    } 
 
    /** 
     * Get an input stream based on file path or content:// uri 
     * 
     * @param path 
     * @return an input stream 
     * @throws FileNotFoundException