检测文件权限.

@param string $f 文件路径.
@param bool   $r 读
@param bool   $w 写

@return array ['required'=>'','checked'=>'','pass'=>'']
181155
public final static function checkFile($f, $r = true, $w = true) {
        $rst     = [];
        $checked = $required = '';
        if ($r) {
            $required .= '可读';
        }
        if ($w) {
            $required .= '可写';
        }
        if (file_exists($f)) {
            if ($r) {
                $checked = is_readable($f) ? '可读' : '不可读';
            }
            if ($w) {
                if (is_dir($f)) {
                    $len = @file_put_contents($f . '/test.dat', 'test');
                    if ($len > 0) {
                        @unlink($f . '/test.dat');
                        $checked .= '可写';
                    } else {
                        $checked .= '不可写';
                    }
                } else {
                    $checked .= is_writable($f) ? '可写' : '不可写';
                }
            }
        } else {
            $checked = '不存在';
        }
        $rst ['required'] = $required;
        $rst ['checked']  = $checked;
        $rst ['pass']     = $checked == $required;
        $rst ['optional'] = false;

        return $rst;
    }
414130
public static function read($file)
    {
        if (!is_readable($file) || !is_file($file)) {
            return;
        }

        $data = file_get_contents($file);

        if ($data === false) {
            return;
        }

        return $data;
    }
264720
public function parseFile($file)
    {
        if (!file_exists($file)) {
            return false;
        }
        $fh = fopen($file, 'r');
        if (!$fh) {
            return false;
        }
        $ret = $this->parseHandle($fh);
        fclose($fh);
        return $ret;
    }
524590
static void trans_w(FNLPCorpus corpus, String toPath) throws IOException,
	UnsupportedEncodingException, FileNotFoundException {

		BufferedWriter bout = new BufferedWriter(new OutputStreamWriter(
				new FileOutputStream(toPath ), "UTF-8"));
		Iterator<FNLPDoc> it1 = corpus.docs.iterator();
		while(it1.hasNext()){
			FNLPDoc doc = it1.next();
			Iterator<FNLPSent> it2 = doc.sentences.iterator();
			while(it2.hasNext()){
				FNLPSent sent = it2.next();
				if(!sent.hasTag())
					continue;
				for(int i=0;i<sent.size();i++){
					String w = ct.normalize(sent.words[i]);
					bout.write(w);
					bout.write("\t");
					bout.write(sent.tags[i]);
					bout.write("\n");
					bout.write("\n");
					
					String w1 = ChineseTrans.toFullWidth(w);
					if(!w1.equals(w)){
						bout.write(w1);
						bout.write("\t");
						bout.write(sent.tags[i]);
						bout.write("\n");
						bout.write("\n");
					}
					
				}
				bout.write("\n");
			}

		}
		bout.close();
	}
1257681
public function files($directory, $recursive = false)
    {
        $result     = [];
        $recursive  = boolval($recursive);

        if ( ! $this->isDirectory($directory)) return [];

        $items = new FilesystemIterator($directory);

        foreach ($items as $item) {
            if ($item->isFile()) {
                $result[]       = $item->getPathname();
            } elseif ($recursive && $item->isDir() && ! $item->isLink()) {
                $subFiles       = $this->files($item->getPathname(), $recursive);
                foreach ($subFiles as $file) {
                    $result[]   = $file;
                }
            }
        }

        return $result;
    }
402473
public static function init_file_direct($filename, $filesize, $path, $is_full = false, $fsencoding = '') {
        if ($is_full) {
            $dest = $path;
        }
        else {
            $dest = WEB_ROOT . $path;
        }

        $dest = self::conv_to($dest, $fsencoding);
        self::mkdir(dirname($dest));

        $dh = fopen($dest, 'w+');
        if ($dh === false) {
            throw new Exception('文件建立失败');
        }
        if (!ftruncate($dh, $filesize)) {
            unlink($dest);
            throw new Exception('文件建立失败');
        }
        fclose($dh);

        $cfg_path = $dest . '.ucfg';
        $dh = fopen($cfg_path, 'w+');
        if ($dh === false) {
            throw new Exception('文件建立失败');
        }
        fclose($dh);

        return $path;
    }
896374
function filesFilter( f, files ) {
        var cwd = f.cwd || '',
            ret = [],
            process = function( file ) {
                var fileinfo = path.join( cwd, file ),
                    dirpath = path.dirname( fileinfo ),
                    depends = [],
                    str, matches, idx;

                if ( !grunt.file.exists( fileinfo ) ) {
                    return;
                }

                ret.push( file );

                str = grunt.file.read( fileinfo );

                // 从require( dps )中找
                // 从defind( id?, dps, factory )中找
                str = str.replace( /(?:define|require)\s*\(\s*\[([^\]]+?)\],/g, function( _, m1 ) {
                    m1 = m1.replace(/\s/g, '').split(',');
                    depends = depends.concat( m1.map(function( item ) {
                        item = item.substring( 1, item.length - 1 );
                        item = item.substring(0, 1) === '.' ?
                                path.join( dirpath, item ):
                                path.join( cwd, item );

                        return path.relative( cwd, item ) + '.js';
                    }) );

                    return _;
                });

                str = str.replace( /require\s*\(\s*('|")(.+?)\1/g, function( _, m1, item ) {


                    item = item.substring(0, 1) === '.' ?
                            path.join( dirpath, item ):
                            path.join( cwd, item );

                    depends.push( path.relative( cwd, item ) + '.js' );

                    return _;
                });

                if ( depends.length ) {
                    depends = depends.filter(function( item, idx, array ) {
                        return array.indexOf( item ) === idx && grunt.file.exists( path.join( cwd, item ) );
                    });

                    idx = ret.indexOf( file );
                    [].splice.apply( ret, [ idx, 0 ].concat( depends ) );
                    depends.forEach( process );
                }
            };
        // console.log( files );
        files.forEach( process );
        ret = ret.filter(function( item, idx, arr ){
            return idx === arr.indexOf( item );
        });


        ret.unshift( path.relative( cwd, intro ) );
        ret.push( path.relative( cwd, outro ) );
        return ret;
    }
554407
public function getLocalFile($file = '') {
        #判断数据不为空
        if (empty($file)) {
            return [];
        }
        $data = [];
        foreach ($file as $key => $value) {
            $path = ROOT_DIR . $value['name'];
            if (is_file($path)) {
                #获取文件内容
                $value['content'] = encrypt(file_get_contents($path));
                $data[]           = $value;
            }
        }
        return $data;
    }
397823
public function getReaderForFile($filename, $mode, $use_include_path, $context)
    {
        $readers = $this->readers;
        if (!isset($readers[$filename])) {
            $reader = new BufferedFileRead();
            $result = $reader->fopen($filename, $mode, $use_include_path, $context);

            return $this->readers[$filename] = $result ? $reader : null;
        }
        return $readers[$filename];
    }
1296625
public function fopen($filename, $mode, $use_include_path = null, $context = null) {

        if ($mode !== self::MODE_READ_BINARY) {
            $message = sprintf(
                "unsupported mode '%s', only '%s' is supported for buffered file read", $mode, self::MODE_READ_BINARY
            );
            trigger_error($message);

            return false;
        }

        if ($context === null) {
            $handle = fopen($filename, self::MODE_READ_BINARY, $use_include_path);
        } else {
            $handle = fopen($filename, self::MODE_READ_BINARY, $use_include_path, $context);
        }

        if (!$handle) {
            return false;
        }

        $this->file   = $filename;
        $this->handle = $handle;

        return true;
    }
1259654
def get_wf_from_path(self, path):
        
        with open(path) as fp:
            content = fp.read()
        return [(os.path.basename(os.path.splitext(path)[0]), content), ]
24315
protected function _read($file) {
		$text = file_get_contents($file);
		if (empty($text)) {
			return [];
		}
		$pieces = explode(NL, $text);
		return $pieces;
	}
427871
public static function file2array($file)
    {
        $aFile = [];
        if ($file instanceof UploadedFile) {
            $aFile = file($file->getRealPath());
        } elseif (is_array($file) && isset($file[0]) && is_string($file[0])) {
            $aFile = $file;
        } elseif (is_string($file) && is_file($file) && file_exists($file)) {
            $aFile = file($file);
        } elseif (is_string($file) && strstr($file, PHP_EOL) !== false) {
            $file_content = explode(PHP_EOL, $file);
            if (empty(end($file_content))) {
                array_pop($file_content);
            }
            reset($file_content);
            $aFile = $file_content;
        }

        return array_map('\ForceUTF8\Encoding::toUTF8', $aFile);
    }
368753
static function read($file)
	{
		if(file_exists($file) && is_readable($file))
			return file_get_contents($file);

		foreach(bors_dirs() as $dir)
			if(file_exists($fn = $dir.'/data/'.$file) && is_readable($fn))
				return file_get_contents($fn);

		return NULL;
	}
1324291
private static List<String> getPathList(File f) {
		List<String> l = new ArrayList<String>();
		File r;
		try {
			r = f.getCanonicalFile();
			while(r != null) {
				l.add(r.getName());
				r = r.getParentFile();
			}
		}
		catch (IOException e) {
			e.printStackTrace();
			l = null;
		}
		return l;
	}
1277630
static function parse_file( $f ){
		$src = file_get_contents( $f, true );
		if( $src === false ){
			throw new Exception("Cannot read file $f");
		}
		return self::parse_string( $src );
	}
842023
private static String matchPathLists(List<String> r,List<String> f) {
		int i;
		int j;
		String s;
		// start at the beginning of the lists
		// iterate while both lists are equal
		s = "";
		i = r.size()-1;
		j = f.size()-1;

		// first eliminate common root
		while((i >= 0)&&(j >= 0)&&(r.get(i).equals(f.get(j)))) {
			i--;
			j--;
		}

		// for each remaining level in the home path, add a ..
		for(;i>=0;i--) {
			s += ".." + File.separator;
		}

		// for each level in the file path, add the path
		for(;j>=1;j--) {
			s += f.get(j) + File.separator;
		}

		// file name
		s += f.get(j);
		return s;
	}