當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。