本文整理了Java中java.io.BufferedWriter.write()
方法的一些代码示例,展示了BufferedWriter.write()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。BufferedWriter.write()
方法的具体详情如下:
包路径:java.io.BufferedWriter
类名称:BufferedWriter
方法名:write
[英]Writes the character oneChar to this writer. If the buffer gets full by writing this character, this writer is flushed. Only the lower two bytes of the integer oneChar are written.
[中]将字符oneChar写入此编写器。如果写入此字符后缓冲区已满,则刷新此写入程序。只写入整数oneChar的下两个字节。
代码示例来源:origin: apache/storm
private void writeString(String str) throws IOException {
processIn.write(str);
processIn.write("\nend\n");
processIn.flush();
}
代码示例来源:origin: hankcs/HanLP
@Override
protected void convertCorpus(Sentence sentence, BufferedWriter bw) throws IOException
{
List<String[]> collector = Utility.convertSentenceToNER(sentence, tagSet);
for (String[] tuple : collector)
{
bw.write(tuple[0]);
bw.write('\t');
bw.write(tuple[1]);
bw.write('\t');
bw.write(tuple[2]);
bw.newLine();
}
}
代码示例来源:origin: stanfordnlp/CoreNLP
public static void print(String[][] cols) throws Exception {
BufferedWriter out = new BufferedWriter(new FileWriter(outputFilename));
for (String[] col : cols) {
if (col.length >= 2) {
out.write(col[0] + "\t" + col[1] + "\n");
} else {
out.write("\n");
}
}
out.flush();
out.close();
}
代码示例来源:origin: embulk/embulk
public static void main(String[] args) throws Exception {
System.out.println(Arrays.asList(args));
File thisFolder = new File(SelfrunTest.class.getResource("/org/embulk/cli/DummyMain.class").toURI()).getParentFile();
try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(thisFolder, "args.txt")), Charset.defaultCharset()))) {
for (String arg : args) {
writer.write(arg);
writer.newLine();
}
}
}
}
代码示例来源:origin: org.testng/testng
public static void writeFile(String string, File f) throws IOException {
f.getParentFile().mkdirs();
try (FileWriter fw = new FileWriter(f);
BufferedWriter bw = new BufferedWriter(fw)) {
bw.write(string);
}
}
代码示例来源:origin: apache/ignite
/**
* @throws Exception If failed.
*/
private void beforeJob() throws Exception {
IgniteFileSystem igfs = grid(0).fileSystem(HadoopAbstractSelfTest.igfsName);
igfs.clear();
igfs.mkdirs(new IgfsPath(PATH_INPUT));
try (BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(igfs.create(
new IgfsPath(PATH_INPUT + "/test.file"), true)))) {
bw.write("word");
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
private Path writeTextTo(final String location) throws IOException {
final Path path = Paths.get(location);
Files.createDirectories(path.getParent());
try (BufferedWriter buffy = Files.newBufferedWriter(path, Charset.defaultCharset())) {
buffy.write("some text");
buffy.newLine();
buffy.flush();
}
return path;
}
}
代码示例来源:origin: hankcs/HanLP
/**
* 导出特征模板
*
* @param templatePath
* @throws IOException
*/
public void dumpTemplate(String templatePath) throws IOException
{
BufferedWriter bw = IOUtil.newBufferedWriter(templatePath);
String template = getTemplate();
bw.write(template);
bw.close();
}
代码示例来源:origin: apache/storm
public static void writeToFile(File file, Set<String> content) throws IOException {
FileWriter fw = new FileWriter(file, false);
BufferedWriter bw = new BufferedWriter(fw);
Iterator<String> iter = content.iterator();
while (iter.hasNext()) {
bw.write(iter.next());
bw.write(System.lineSeparator());
}
bw.close();
}
代码示例来源:origin: apache/flink
/**
* Creates a temporary file that contains the given string.
* The file is written with the platform's default encoding.
*
* <p>The temp file is automatically deleted on JVM exit.
*
* @param contents The contents to be written to the file.
* @return The temp file URI.
*/
public static String createTempFile(String contents) throws IOException {
File f = File.createTempFile("flink_test_", ".tmp");
f.deleteOnExit();
try (BufferedWriter out = new BufferedWriter(new FileWriter(f))) {
out.write(contents);
}
return f.toURI().toString();
}
代码示例来源:origin: apache/flink
private static void writePoint(double[] coordinates, StringBuilder buffer, BufferedWriter out) throws IOException {
buffer.setLength(0);
// write coordinates
for (int j = 0; j < coordinates.length; j++) {
buffer.append(FORMAT.format(coordinates[j]));
if (j < coordinates.length - 1) {
buffer.append(DELIMITER);
}
}
out.write(buffer.toString());
out.newLine();
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
private Path writeTextTo(final String location) throws IOException {
final Path path = Paths.get(location);
Files.createDirectories(path.getParent());
try (BufferedWriter buffy = Files.newBufferedWriter(path, Charset.defaultCharset())) {
buffy.write("some text");
buffy.newLine();
buffy.flush();
}
return path;
}
代码示例来源:origin: facebook/stetho
public void send(String message) throws IOException {
mReporter.onSend(message);
try {
mOutput.write(message + "\r\n");
mOutput.flush();
} catch (IOException e) {
mReporter.onError(e);
throw e;
}
}
代码示例来源:origin: google/guava
public void testNewWriter() throws IOException {
File temp = createTempFile();
try {
Files.newWriter(temp, null);
fail("expected exception");
} catch (NullPointerException expected) {
}
try {
Files.newWriter(null, Charsets.UTF_8);
fail("expected exception");
} catch (NullPointerException expected) {
}
BufferedWriter w = Files.newWriter(temp, Charsets.UTF_8);
try {
w.write(I18N);
} finally {
w.close();
}
File i18nFile = getTestFile("i18n.txt");
assertTrue(Files.equal(i18nFile, temp));
}
代码示例来源:origin: androidannotations/androidannotations
private static boolean writeValue(Socket client, String value) {
boolean result;
BufferedWriter out = null;
try {
OutputStream clientStream = client.getOutputStream();
out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
out.write(value);
out.write("\n");
out.flush();
result = true;
} catch (Exception e) {
result = false;
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
result = false;
}
}
}
return result;
}
代码示例来源:origin: stanfordnlp/CoreNLP
@Override
public void saveToFilename(String file) {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(file))) {
for (int i = 0, sz = size(); i < sz; i++) {
bw.write(i + "=" + get(i) + '\n');
}
} catch (IOException e) {
throw new RuntimeIOException(e);
}
// give up
}
代码示例来源:origin: apache/flink
private static void writePoint(double[] data, StringBuilder buffer, BufferedWriter out) throws IOException {
buffer.setLength(0);
// write coordinates
for (int j = 0; j < data.length; j++) {
buffer.append(FORMAT.format(data[j]));
if (j < data.length - 1) {
buffer.append(DELIMITER);
}
}
out.write(buffer.toString());
out.newLine();
}
}
代码示例来源:origin: org.apache.logging.log4j/log4j-core
private Path writeTextTo(final String location) throws IOException {
final Path path = Paths.get(location);
Files.createDirectories(path.getParent());
try (BufferedWriter buffy = Files.newBufferedWriter(path, Charset.defaultCharset())) {
buffy.write("some text");
buffy.newLine();
buffy.flush();
}
return path;
}
}
代码示例来源:origin: apache/storm
@Override
public void execute(Tuple input) {
Values values = (Values) input.getValue(0);
byte[] array = serializer.write(values, null).array();
String data = new String(array);
try {
writer.write(data + "\n");
writer.flush();
collector.ack(input);
} catch (IOException e) {
LOG.error("Error while writing data to socket.", e);
collector.reportError(e);
collector.fail(input);
}
}
代码示例来源:origin: apache/hive
static void writeFile(File outputFile, String str) throws IOException {
BufferedWriter w = new BufferedWriter(new FileWriter(outputFile));
w.write(str);
w.close();
}
内容来源于网络,如有侵权,请联系作者删除!