本文整理匯總了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();
}
示例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);
}
}
示例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);
}
示例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();
}
}
}
示例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();
}
}
示例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);
}
}
示例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();
}
}
示例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");
}
}
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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());
}
}
示例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);
}
}
示例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);
}
}
示例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]);
}
}
}