简单写入String到File.
183980
public static void write(final CharSequence data, final File file) throws IOException {
		Validate.notNull(file);
		Validate.notNull(data);

		try (BufferedWriter writer = Files.newBufferedWriter(file.toPath(), Charsets.UTF_8)) {
			writer.append(data);
		}
	}
182719
public static String file(File file) throws IOException {
        InputStream in = null;
        try {
            in = new FileInputStream(file);
            return stream(in, file.length());
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
888668
public String readFileContent(File file) {
        StringBuilder fileContentBuilder = new StringBuilder();
        if (file.exists()) {
            String stringLine;
            try {
                FileReader fileReader = new FileReader(file);
                BufferedReader bufferedReader = new BufferedReader(fileReader);
                while ((stringLine = bufferedReader.readLine()) != null) {
                    fileContentBuilder.append(stringLine + "\n");
                }
                bufferedReader.close();
                fileReader.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return fileContentBuilder.toString();
    }
1258079
function processFile(file, encoding) {
    var fileContent = file.contents.toString(encoding),
        matches = fileContent.match(reg$$Global),
        expression,
        tempRegResults,
        name,
        value,
        replaceStr;

    if(null === matches) {
        return file;
    }
    for(var i = 0, len = matches.length; i < len; i ++) {
        expression = matches[i];
        tempRegResults = expression.match(reg$$);
        name = tempRegResults[1];
        value = tempRegResults[2];

        replaceStr = (resolvers[name] || loop)(file, valueProcess(name, value));
        //替换表达式的值为应该替换的那一部分
        fileContent = fileContent.replace(expression, replaceStr.replace("$", "$$$$"));
    }

    file.contents = new Buffer(fileContent);
    return file;
}
531806
@Nonnull
    public static String readFile(@Nonnull File file, @Nonnull Charset charset) throws IOException {
        if (file == null)
            throw new NullPointerException("Given 'file' can not be null");
        if (!file.exists())
            throw new IllegalArgumentException("File " + file.getAbsolutePath() + " does not exist");
        if (file.isDirectory())
            throw new IllegalArgumentException("File " + file.getAbsolutePath() + " can NOT be a directory");

        InputStream in = new BufferedInputStream(new FileInputStream(file));
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        copy(in, bos);
        return new String(bos.toByteArray(), charset);

    }
961633
public void stringToFile(String content, File file) throws IOException {
        stringToOutputStream(content, new FileOutputStream(file));
    }
179535
function getFileExtension(file) {
    return file.name.substring(file.name.lastIndexOf('.')+1, file.name.length).toLowerCase()
}
403633
def dump_string_to_file(string, filepath):
    """"""
    create_dirs(
        os.path.dirname(filepath)
    )

    with open(filepath, 'a') as outfile:
        outfile.write(string)
        outfile.write('\n')
1139536
function ( err ) {
    // 报错文件名
    var fileName = err.fileName;
    // 报错类型
    var name = err.name;
    // 报错信息
    var message = err.message;
    // 出错代码位置
    var loc = err.loc;

    var logInfo = '报错文件：' + fileName + '报错类型：' + name + '出错代码位置：' + loc.line + ',' + loc.column;

    util.log( logInfo );

    this.end();
}
324533
private static void extractText(Path file, BufferedWriter writer, String separator, boolean includePhrase){
        try(BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file.toFile()),"utf-8"));){
            String line;
            while( (line = reader.readLine()) != null ){
                //去除首尾空白字符
                line = line.trim();
                //忽略空行
                if(!"".equals(line)){
                    //词和词之间以空格隔开
                    String[] words = line.split("\\s+");
                    if(words == null){
                        //忽略不符合规范的行
                        continue;
                    }
                    StringBuilder phrase = new StringBuilder();
                    int phraseCount=0;
                    boolean find=false;
                    for(String word : words){
                        String[] attr = word.split("/");
                        if(attr == null || attr.length < 1){
                            //忽略不符合规范的词
                            continue;
                        }
                        if(attr[0].trim().startsWith("[")){
                            find = true;
                        }                        
                        //去掉[和]
                        String item = attr[0].replace("[", "").replace("]", "").trim();
                        writer.write(item+separator);
                        if(find){
                            phrase.append(item);
                            phraseCount++;
                        }
                        //短语标注错误
                        if(phraseCount > 10){
                            find = false;
                            phraseCount = 0;
                            phrase.setLength(0);
                        }
                        if(find && attr.length > 1 && attr[1].trim().endsWith("]")){
                            find = false;
                            if(includePhrase){
                                writer.write(phrase.toString()+separator);
                            }
                            phrase.setLength(0);
                        }
                        //词数目
                        WORD_COUNT.incrementAndGet();
                        //字符数目
                        CHAR_COUNT.addAndGet(item.length());
                    }
                    //换行
                    writer.write("\n");
                }
            }
        }catch(Exception e){
            LOGGER.info("从语料库 "+file+" 中抽取文本失败：", e);
        }        
    }
1343519
public static String path(String file) {
      if (StringUtils.isNullOrBlank(file)) {
         return StringUtils.EMPTY;
      }
      file = StringUtils.trim(file);
      int pos = indexOfLastSeparator(file);
      return pos == file.length() - 1 ? file.substring(0, file.length() - 1) : file;
   }
1012539
def readme(filename, encoding='utf8'):
    

    with io.open(filename, encoding=encoding) as source:
        return source.read()
711685
private static void clean(String file) throws IOException {
		
		StringBuffer sb = new StringBuffer();
		BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file),Charset.forName("utf8")));
		String str;
		while((str = br.readLine())!=null){
			if(str.length()!=0&&!str.trim().startsWith("<")){
				if(str.equalsIgnoreCase("root"))
					continue;
				if(str.contains("</HEADER> ")||str.contains("</HEADLINE>"))
					continue;
				sb.append(str+"\n");

			}				
		}

		br.close();
		Writer wr = new OutputStreamWriter(new FileOutputStream(new File(file)),Charset.forName("gbk"));//输出目录
		wr.write(sb.toString());
		wr.close();

	}
817205
function watchOnFile(file, callback) {
  let lastIndex = 0
  let timer

  function read() {
    const stat = fs.statSync(file)

    if (stat.size !== lastIndex) {
      const fd = fs.openSync(file, 'r')
      const buffer = Buffer.alloc(stat.size - lastIndex)

      try {
        fs.readSync(fd, buffer, lastIndex, stat.size - lastIndex)
        const content = buffer.toString('utf8')
        lastIndex = stat.size

        callback(content)
      } catch (error) {
        // 从头读起
        lastIndex = 0
      }
    }

    timer = setTimeout(read, 200)
  }

  read()
  return function() {
    clearTimeout(timer)
  }
}
167363
private String[] list(File file) {
        String[] files = (String[]) fileListMap.get(file);
        if (files == null) {
            files = file.list();
            if (files != null) {
                fileListMap.put(file, files);
            }
        }
        return files;
    }
1240717
function(file) {
            var me = this;

            // 移出invalid的文件
            $.each( me.request( 'get-files', Status.INVALID ), function() {
                me.request( 'remove-file', this );
            });

            // 如果指定了开始某个文件，则只开始指定的文件。
            if ( file ) {
                file = file.id ? file : me.request( 'get-file', file );

                if (file.getStatus() === Status.INTERRUPT) {
                    file.setStatus( Status.QUEUED );

                    $.each( me.pool, function( _, v ) {

                        // 之前暂停过。
                        if (v.file !== file) {
                            return;
                        }

                        v.transport && v.transport.send();
                        file.setStatus( Status.PROGRESS );
                    });

                    
                } else if (file.getStatus() !== Status.PROGRESS) {
                    file.setStatus( Status.QUEUED );
                }
            } else {
                $.each( me.request( 'get-files', [ Status.INITED ] ), function() {
                    this.setStatus( Status.QUEUED );
                });
            }

            if ( me.runing ) {
                me.owner.trigger('startUpload', file);// 开始上传或暂停恢复的，trigger event
                return Base.nextTick( me.__tick );
            }

            me.runing = true;
            var files = [];

            // 如果有暂停的，则续传
            file || $.each( me.pool, function( _, v ) {
                var file = v.file;

                if ( file.getStatus() === Status.INTERRUPT ) {
                    me._trigged = false;
                    files.push(file);

                    if (v.waiting) {
                        return;
                    }
                    
                    // 文件 prepare 完后，如果暂停了，这个时候只会把文件插入 pool, 而不会创建 tranport，
                    v.transport ? v.transport.send() : me._doSend(v);
                }
            });

            $.each(files, function() {
                this.setStatus( Status.PROGRESS );
            });

            file || $.each( me.request( 'get-files',
                    Status.INTERRUPT ), function() {
                this.setStatus( Status.PROGRESS );
            });

            me._trigged = false;
            Base.nextTick( me.__tick );
            me.owner.trigger('startUpload');
        }
144165
def read_file(path):
    """"""
    file_path = os.path.join(here, *path)
    with open(file_path, encoding="utf-8") as f:
        return f.read()