java类java.io.BufferedWriter的实例源码

FileManager.java 文件源码 项目:Scraping-AvvisiDMI 阅读 28 收藏 0 点赞 0 评论 0
public static void scrivi(File file, String string) throws IOException {
    FileWriter fw = new FileWriter(file);
    BufferedWriter bw = new BufferedWriter(fw);
    bw.write(string+"\n");
    bw.flush();
    bw.close();
}
TrieDictionaryTest.java 文件源码 项目:incubator-netbeans 阅读 18 收藏 0 点赞 0 评论 0
private Dictionary constructTrie(SortedSet<String> data) throws Exception {
    clearWorkDir();

    File sourceFile = new File(getWorkDir(), "source");
    Writer w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(sourceFile), "UTF-8"));

    for (String d : data) {
        w.write(d);
        w.write("\n");
    }

    w.close();

    File trieFile = new File(getWorkDir(), "dict");

    return TrieDictionary.getDictionary(trieFile, Collections.<URL>singletonList(sourceFile.toURI().toURL()));
}
DiseaseParser.java 文件源码 项目:Botanist 阅读 17 收藏 0 点赞 0 评论 0
/**
 * Create a parser for diseases file
 * @param inputFileName - plant disease csv
 * @param outputFileName - firebase .json
 * @throws IOException if a read/write error occurs
 */
public DiseaseParser(String inputFileName, String outputFileName) throws IOException {
    input = new File(inputFileName);
    output = new File(outputFileName);
    br = new BufferedReader(new FileReader(input));
    bw = new BufferedWriter(new FileWriter(output));
    familyDiseaseMap = new HashMap<String, List<String>>();
    diseaseUrls = parseDiseaseUrls(DISEASE_REFS_FILE);
}
LibraryProtoWriter.java 文件源码 项目:rejoiner 阅读 17 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws IOException {
  if (args.length == 0) {
    throw new RuntimeException("output path required");
  }
  String proto = SchemaToProto.toProto(LibrarySchema.SCHEMA);
  BufferedWriter writer = Files.newWriter(new File(args[0]), Charsets.UTF_8);
  try {
    writer.write(proto);
  } finally {
    writer.close();
  }
}
Metrics.java 文件源码 项目:bStats-Metrics 阅读 30 收藏 0 点赞 0 评论 0
/**
 * Writes a String to a file. It also adds a note for the user,
 *
 * @param file The file to write to. Cannot be null.
 * @param text The text to write.
 * @throws IOException If something did not work :(
 */
private void writeFile(File file, String text) throws IOException {
    if (!file.exists()) {
        file.createNewFile();
    }
    try (
            FileWriter fileWriter = new FileWriter(file);
            BufferedWriter bufferedWriter = new BufferedWriter(fileWriter)
    ) {
        bufferedWriter.write(text);
        bufferedWriter.newLine();
        bufferedWriter.write("Note: This class only exists for internal purpose. You can ignore it :)");
    }
}
SqlExecutorStepTest.java 文件源码 项目:gretl 阅读 18 收藏 0 点赞 0 评论 0
private File createSqlFileWithWrongExtension() throws Exception{
    File sqlFile =  folder.newFile("query.txt");
    BufferedWriter writer = new BufferedWriter(new FileWriter(sqlFile));
    writer.write(" INSERT INTO colors\n" +
            "VALUES (124,252,0,'LawnGreen')");
    writer.close();
    return sqlFile;
}
TestConfiguration.java 文件源码 项目:hadoop 阅读 28 收藏 0 点赞 0 评论 0
/**
 * Tests use of multi-byte characters in property names and values.  This test
 * round-trips multi-byte string literals through saving and loading of config
 * and asserts that the same values were read.
 */
public void testMultiByteCharacters() throws IOException {
  String priorDefaultEncoding = System.getProperty("file.encoding");
  try {
    System.setProperty("file.encoding", "US-ASCII");
    String name = "multi_byte_\u611b_name";
    String value = "multi_byte_\u0641_value";
    out = new BufferedWriter(new OutputStreamWriter(
      new FileOutputStream(CONFIG_MULTI_BYTE), "UTF-8"));
    startConfig();
    declareProperty(name, value, value);
    endConfig();

    Configuration conf = new Configuration(false);
    conf.addResource(new Path(CONFIG_MULTI_BYTE));
    assertEquals(value, conf.get(name));
    FileOutputStream fos = new FileOutputStream(CONFIG_MULTI_BYTE_SAVED);
    try {
      conf.writeXml(fos);
    } finally {
      IOUtils.closeStream(fos);
    }

    conf = new Configuration(false);
    conf.addResource(new Path(CONFIG_MULTI_BYTE_SAVED));
    assertEquals(value, conf.get(name));
  } finally {
    System.setProperty("file.encoding", priorDefaultEncoding);
  }
}
LSDRuleEnumerator.java 文件源码 项目:RefDiff 阅读 23 收藏 0 点赞 0 评论 0
public LSDRuleEnumerator(File twoKBFile, File deltaKBFile,
        File winnowingRulesFile, File resultsFile, int minConcFact,
        double accuracy, int k, int beamSize2, int maxException,
        File modifiedWinnowingRulesFile, BufferedWriter output)
        throws Exception {
    setMinMatchesPerLiteral(0);
    setMaxExceptions(maxException);
    setBeamSize(beamSize);
    setMinMatches(minConcFact);
    setMinAccuracy(accuracy);
    setAntecedentSize(k);
    this.output = output;
    this.fb = new LSDFactBase();
    // reads input files and builds lists of facts
    startTimer();
    read2kbFacts = new LSDTyrubaFactReader(twoKBFile).getFacts();
    readDeltaFacts = new LSDTyrubaFactReader(deltaKBFile).getFacts();
    winnowingRules = new LSDAlchemyRuleReader(winnowingRulesFile)
            .getRules();

    // set onDemand database manipulators
    onDemand2KB = new LSdiffDistanceFactBase(read2kbFacts, readDeltaFacts);
    onDemandDeltaKB = new LSdiffHierarchialDeltaKB(readDeltaFacts);

    // set the modified winnowing rules
    modifiedWinnowingRules = new LSDAlchemyRuleReader(new File(
            MetaInfo.modifiedWinnowings)).getRules();
    stopTimer();
}
LoadableProperties.java 文件源码 项目:SER316-Dresden 阅读 49 收藏 0 点赞 0 评论 0
public void save(OutputStream outStream) throws IOException {
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(outStream, "UTF-8"));
    String aKey;
    Object aValue;
    for (Enumeration e = keys(); e.hasMoreElements();) {
        aKey = (String) e.nextElement();
        aValue = get(aKey);
        out.write(aKey + " = " + aValue);
        out.newLine();
    }
    out.flush();
    out.close();
}
WorkflowEditorDropTargetListener.java 文件源码 项目:KernelHive 阅读 16 收藏 0 点赞 0 评论 0
private List<IKernelFile> copyKernelsFromTemplates(
        final KernelRepositoryEntry kre, final File rootDir)
        throws SecurityException, IOException {
    final List<IKernelFile> sourceFiles = new ArrayList<IKernelFile>(kre
            .getKernelPaths().size());
    for (final KernelPathEntry kpe : kre.getKernelPaths()) {
        final BufferedReader br = new BufferedReader(new InputStreamReader(
                kpe.getPath().openConnection().getInputStream()));

        final File file = FileUtils.createNewFile(rootDir.getAbsolutePath()
                + System.getProperty("file.separator") + kpe.getName());

        final BufferedWriter bw = new BufferedWriter(new FileWriter(file));

        String line = br.readLine();
        while (line != null) {
            bw.write(line);
            bw.newLine();
            line = br.readLine();
        }
        bw.flush();
        bw.close();
        br.close();

        sourceFiles.add(new KernelFile(file, kpe.getId(), kpe
                .getProperties()));
    }
    return sourceFiles;
}


问题


面经


文章

微信
公众号

扫码关注公众号