当前位置: 首页>>代码示例>>Java>>正文


Java Files.newBufferedWriter方法代码示例

本文整理汇总了Java中java.nio.file.Files.newBufferedWriter方法的典型用法代码示例。如果您正苦于以下问题:Java Files.newBufferedWriter方法的具体用法?Java Files.newBufferedWriter怎么用?Java Files.newBufferedWriter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.file.Files的用法示例。


在下文中一共展示了Files.newBufferedWriter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateBigXmlFile

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Generate a BIG xml file: temporary/bigfile.xml
 */
@Test
@Ignore
public void generateBigXmlFile() throws IOException {

    // make temporary/ dir if it doesn't exist
    Path temporaryPath = Paths.get(Constants.TMP_PATH);
    if (!Files.exists(temporaryPath)) {
        Files.createDirectory(temporaryPath);
    }

    // dump loads of xml in temporary/bigfile.xml
    BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(Constants.BIG_XML_FILE_PATH));
    PrintWriter printWriter = new PrintWriter(bufferedWriter);
    printWriter.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    printWriter.println("<rootelement>");

    IntStream
            .rangeClosed(1, Integer.parseInt(TestProperties.getProperty("com.guido.test.upload.bigfile")))
            .forEach(i -> printWriter.println( String.format("<childelement id=\"%d\">HELLO%10d</childelement>", i, i) ));

    printWriter.println("</rootelement>");
    printWriter.flush();
    printWriter.close();

}
 
开发者ID:guido-n,项目名称:mule-useful-experiments,代码行数:29,代码来源:BigXMLFileGenerator.java

示例2: save

import java.nio.file.Files; //导入方法依赖的package包/类
private void save() {
    try {
        Path p = Options.path.resolve("recentfiles");
        Log.info("Save recent files to file: " + p);
        if (Files.notExists(p)) {
            Files.createFile(p);
        }
        try (PrintWriter pw = new PrintWriter(Files.newBufferedWriter(p))) {
            for (RecentFile recentFile : list) {
                pw.println(recentFile);
            }
        }
    } catch (IOException e) {
        Log.error(e);
    }
}
 
开发者ID:Glavo,项目名称:ClassViewer,代码行数:17,代码来源:RecentFiles.java

示例3: CsvMpiStatistics

import java.nio.file.Files; //导入方法依赖的package包/类
public CsvMpiStatistics(Path dbDir, String dbName) throws IOException {
    Objects.requireNonNull(dbDir);
    Objects.requireNonNull(dbName);
    this.dbDir = dbDir;
    this.dbName = dbName;
    Path csvFile = dbDir.resolve(dbName + ".csv");
    // if file already exists, create a backup
    if (Files.exists(csvFile)) {
        int i = 1;
        Path savCsvFile;
        do {
            savCsvFile = csvFile.getParent().resolve(csvFile.getFileName() + "." + i++);
        } while (Files.exists(savCsvFile));
        Files.move(csvFile, savCsvFile);
    }
    internalWriter = Files.newBufferedWriter(csvFile, StandardCharsets.UTF_8);
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:18,代码来源:CsvMpiStatistics.java

示例4: createFileByTemplate

import java.nio.file.Files; //导入方法依赖的package包/类
public static void createFileByTemplate(Path template, Path out, Map<String, Object> model) throws IOException {
    if (Files.exists(out) && Files.isRegularFile(out)) {
        try {
            Files.delete(out);
        } catch (Exception ex) {
            System.out.println("WARNING: " + out.toFile().getAbsolutePath() + " already exists - unable to remove old copy");
            ex.printStackTrace();
        }
    }

    try (BufferedReader br = Files.newBufferedReader(template, Charset.defaultCharset());
         BufferedWriter bw = Files.newBufferedWriter(out, Charset.defaultCharset())) {
        String line;
        while ((line = br.readLine()) != null) {
            if (model != null) {
                for (Map.Entry<String, Object> macro : model.entrySet()) {
                    line = line.replaceAll(Pattern.quote(macro.getKey()), macro.getValue().toString());
                }
            }

            bw.write(line, 0, line.length());
            bw.newLine();
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:RmiRegistrySslTest.java

示例5: setTypeLabelID

import java.nio.file.Files; //导入方法依赖的package包/类
public void setTypeLabelID(long type_label_id) throws IOException {

        if (this.type_label_id != -1) {
            throw new IOException("Type label already set");
        }
        this.type_label_id = type_label_id; // cache it and keep a persistent copy of the label.

        Path path = directory.toPath();
        Path meta_path = path.resolve(META_BUCKET_NAME);
        FileManipulation.createDirectoryIfDoesNotExist(meta_path);

        Path typepath = meta_path.resolve(TYPE_LABEL_FILE_NAME);
        if (Files.exists(typepath)) {
            throw new IOException("Type label already set");
        }
        FileManipulation.createFileIfDoesNotExist((typepath));

        try (BufferedWriter writer = Files.newBufferedWriter(typepath, FileManipulation.FILE_CHARSET)) {

            writer.write(Long.toString(type_label_id)); // Write the id of the typelabel OID into this field.
            writer.newLine();
        }
    }
 
开发者ID:stacs-srg,项目名称:storr,代码行数:24,代码来源:DirectoryBackedBucket.java

示例6: dump

import java.nio.file.Files; //导入方法依赖的package包/类
public void dump(Path file) throws IOException {
    try (BufferedWriter writer = Files.newBufferedWriter(file, Charset.forName("UTF-8"))) {
        dump(writer);
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:6,代码来源:StringToIntMapper.java

示例7: exportBaudPeriodsCsv

import java.nio.file.Files; //导入方法依赖的package包/类
private void exportBaudPeriodsCsv(String fileName, Set<BaudEntryPeriod> periods) {
    File f = new File(fileName);
    try(BufferedWriter bw = Files.newBufferedWriter(f.toPath(), Charset.forName("UTF-8"), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)) {
        bw.write(BaudEntryPeriod.CSV_HEADER);
        bw.newLine();
        for(BaudEntryPeriod period : periods) {
            bw.write(period.toCsvString());
            bw.newLine();
        }
    } catch(Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:ivandavidov,项目名称:baud,代码行数:14,代码来源:Main.java

示例8: initTestFile

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Creates file blah of specified size in bytes.
 */
private static void initTestFile(File blah, long size) throws Exception {
    try (BufferedWriter writer = Files.newBufferedWriter(blah.toPath(), ISO_8859_1)) {
        for(int i=0; i<size; i++) {
            writer.write("e");
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:11,代码来源:Truncate.java

示例9: writeChefRequest

import java.nio.file.Files; //导入方法依赖的package包/类
/**
 * Gets cookbook path by ciClassname
 */
protected void writeChefRequest(CmsWorkOrderSimpleBase wo, String fileName) {
  // build a chef request
  Map<String, Object> chefRequest = assembleRequest(wo);
  // write the request to a .json file
  try (BufferedWriter out = Files.newBufferedWriter(Paths.get(fileName))) {
    out.write(gsonPretty.toJson(chefRequest));
  } catch (IOException e) {
    logger.error("Exception occurred in writing", e);
  }
}
 
开发者ID:oneops,项目名称:oneops,代码行数:14,代码来源:AbstractOrderExecutor.java

示例10: save

import java.nio.file.Files; //导入方法依赖的package包/类
public void save(Path file) throws IOException {
	String fn = file.getFileName().toString();

	if (fn.endsWith(".csv")) {
		try (BufferedWriter out = Files.newBufferedWriter(file)) {
			saveCSV(out);
		}
	} else {
		try (DataOutputStream out = new DataOutputStream(Files.newOutputStream(file))) {
			save(out);
		}
	}
}
 
开发者ID:Yeregorix,项目名称:EpiStats,代码行数:14,代码来源:RankingList.java

示例11: process

import java.nio.file.Files; //导入方法依赖的package包/类
private void process(Path inFile, Path outFile) throws IOException {
  try (BufferedReader in = Files.newBufferedReader(inFile)) {
    try (BufferedWriter out = Files.newBufferedWriter(outFile)) {
      process(in, out);
    }
  }
}
 
开发者ID:xemantic,项目名称:github-users-web,代码行数:8,代码来源:PrepareGwtJs.java

示例12: overwrite

import java.nio.file.Files; //导入方法依赖的package包/类
public void overwrite() {
    try {
        Path javaFilePath = Paths.get(this.targetFolderPath + path);
        try (BufferedWriter writer = Files.newBufferedWriter(javaFilePath, StandardCharsets.UTF_8)) {
            writer.write(compilationUnit.toString());
        } catch (IOException x) {
            System.err.format("IOException: %s%n", x);
        }
    } catch (Exception e) {
        System.out.println("Error occured while opening the given file: " + e.getMessage());
    }
}
 
开发者ID:kaanburaksener,项目名称:octoBubbles,代码行数:13,代码来源:AbstractStructure.java

示例13: writeFile

import java.nio.file.Files; //导入方法依赖的package包/类
private static void writeFile(String content, Path base, String... pathElements) {
    try {
        Path file = resolveFile(base, pathElements);

        Files.createDirectories(file.getParent());

        try (Writer out = Files.newBufferedWriter(file)) {
            out.append(content);
        }
    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:AnnotationProcessing.java

示例14: print

import java.nio.file.Files; //导入方法依赖的package包/类
@SuppressWarnings("unused")
public void print(final Path path) throws IOException {

    try (Writer writer = Files.newBufferedWriter(path)) {
        print(writer);
    }
}
 
开发者ID:stacs-srg,项目名称:ciesvium,代码行数:8,代码来源:DataSet.java

示例15: generateOutput

import java.nio.file.Files; //导入方法依赖的package包/类
void generateOutput(String... args) throws Exception {
    Predicate<String> ignoreList = constructAcceptIgnoreList(args[1]);
    for (int i = 2; i < args.length; i += 4) {
        try (Writer actual = Files.newBufferedWriter(Paths.get(args[i + 2]));
             Writer expected = Files.newBufferedWriter(Paths.get(args[i + 3]))) {
            run(actual, args[i + 1]);
            realClasses(args[i], ignoreList, expected, args[i + 1]);
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:ElementStructureTest.java


注:本文中的java.nio.file.Files.newBufferedWriter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。