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


Java BufferedWriter.write方法代码示例

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


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

示例1: writeLongToFile

import java.io.BufferedWriter; //导入方法依赖的package包/类
/**
* Write a long value to disk atomically. Either succeeds or an exception
* is thrown.
* @param name file name to write the long to
* @param value the long value to write to the named file
* @throws IOException if the file cannot be written atomically
*/
  private void writeLongToFile(String name, long value) throws IOException {
      File file = new File(logFactory.getSnapDir(), name);
      AtomicFileOutputStream out = new AtomicFileOutputStream(file);
      BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
      boolean aborted = false;
      try {
          bw.write(Long.toString(value));
          bw.flush();
          
          out.flush();
      } catch (IOException e) {
          LOG.error("Failed to write new file " + file, e);
          // worst case here the tmp file/resources(fd) are not cleaned up
          //   and the caller will be notified (IOException)
          aborted = true;
          out.abort();
          throw e;
      } finally {
          if (!aborted) {
              // if the close operation (rename) fails we'll get notified.
              // worst case the tmp file may still exist
              out.close();
          }
      }
  }
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:33,代码来源:QuorumPeer.java

示例2: writetxt

import java.io.BufferedWriter; //导入方法依赖的package包/类
public static void writetxt(String txtPath, String txtCont)
{
	try
	{
		File f = new File(txtPath);
		if (!f.exists())
		{
			f.createNewFile();
		}
		OutputStreamWriter write = new OutputStreamWriter(new FileOutputStream(f,true), "UTF-8");
		BufferedWriter writer = new BufferedWriter(write);
		writer.write(txtCont);
		writer.close();
	} catch (Exception e)
	{
		e.printStackTrace();
	}
}
 
开发者ID:guozhaotong,项目名称:FacetExtract,代码行数:19,代码来源:aSaveContentAllTopics.java

示例3: writeStringToFile

import java.io.BufferedWriter; //导入方法依赖的package包/类
public void writeStringToFile(String string, String fileName) {
    try {
        // Assume default encoding.
        java.io.FileWriter fileWriter =
                new java.io.FileWriter(fileName);

        // Always wrap FileWriter in BufferedWriter.
        BufferedWriter bufferedWriter =
                new BufferedWriter(fileWriter);

            bufferedWriter.write("" + string);

        // Always close files.
        bufferedWriter.close();
    }
    catch(IOException ex) {
        System.out.println(
                "Error writing to file '"
                        + fileName + "'");
        // Or we could just do this:
        // ex.printStackTrace();
    }
}
 
开发者ID:fredkneeland,项目名称:DNA_Analysis,代码行数:24,代码来源:FileWriter.java

示例4: writePajekFormat

import java.io.BufferedWriter; //导入方法依赖的package包/类
public void writePajekFormat(File f) throws IOException {
	BufferedWriter w = new BufferedWriter(new FileWriter(f));
	
	w.write(String.format("*Vertices %d\n", graph.getGraphNodes().size()));
	for(Node<TNode> n : graph.getGraphNodes()) {
		Integer partition = nodes.get(n.getData());
		
		if(partition==null) {
			partition = 0;
		}
		
		w.write(String.format("%d\n", partition));
	}
	
	w.close();
}
 
开发者ID:olehmberg,项目名称:winter,代码行数:17,代码来源:Partitioning.java

示例5: writeLine

import java.io.BufferedWriter; //导入方法依赖的package包/类
private void writeLine(BufferedWriter writer, int indentLevel, int indentLevelIncrease, String... parts)
        throws IOException {
    writeIndent(writer, indentLevel);
    int len = indentLevel * 4;
    for (int i = 0; i < parts.length; i++) {
        String part = parts[i];
        if (i != 0) {
            if (len + part.length() > 118) {
                writer.write("\n");
                if (indentLevel < 12) {
                    indentLevel += indentLevelIncrease;
                }
                writeIndent(writer, indentLevel);
                len = indentLevel * 4;
            } else {
                writer.write(" ");
            }
        }
        writer.write(part);
        len += part.length();
    }
    writer.write("\n");
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:EventBusAnnotationProcessor.java

示例6: save

import java.io.BufferedWriter; //导入方法依赖的package包/类
public void save(OutputStream outStream, boolean sorted) throws IOException {
	if (!sorted) {
		save(outStream);
		return;
	}
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(outStream, "UTF-8"));
    String aKey;
    Object aValue;
    TreeMap tm = new TreeMap(this);
    for (Iterator i = tm.keySet().iterator(); i.hasNext();) {
        aKey = (String) i.next();
        aValue = get(aKey);
        out.write(aKey + " = " + aValue);
        out.newLine();
    }
    out.flush();
    out.close();
}
 
开发者ID:ser316asu,项目名称:Reinickendorf_SER316,代码行数:19,代码来源:LoadableProperties.java

示例7: write

import java.io.BufferedWriter; //导入方法依赖的package包/类
@Override
public FileWriteResult write(@NonNull File file, @NonNull String text, @NonNull PercentSender percentSender) {
    try {
        if (!file.exists() || !file.canWrite()) {
            return FileWriteResult.FAILURE;
        }

        percentSender.refreshPercents(0, 0);

        BufferedWriter writer = new BufferedWriter(new FileWriter(file));
        writer.write(text);

        writer.close();


        percentSender.refreshPercents(0, 100);
    } catch (IOException e) {
        e.printStackTrace();

        return FileWriteResult.FAILURE;
    }

    return FileWriteResult.SUCCESS;
}
 
开发者ID:pashkobohdan,项目名称:FastReading,代码行数:25,代码来源:FileReadingAndWriting.java

示例8: put

import java.io.BufferedWriter; //导入方法依赖的package包/类
public static String put(
        String targetURL,
        String payload,
        String username,
        String password)
        throws IOException
{
    final HttpURLConnection conn = getHttpConnection("PUT", targetURL, username, password);
    if (null == conn) {
        if (ConstantsUI.DEBUG_MODE) {
            Log.d(ConstantsUI.TAG, "Error get connection object: " + targetURL);
        }
        return "0";
    }
    conn.setRequestProperty("Content-type", "application/json");
    // Allow Outputs
    conn.setDoOutput(true);

    OutputStream os = conn.getOutputStream();
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
    writer.write(payload);

    writer.flush();
    writer.close();
    os.close();

    int responseCode = conn.getResponseCode();
    if (responseCode != HttpURLConnection.HTTP_OK) {
        if (ConstantsUI.DEBUG_MODE) {
            Log.d(ConstantsUI.TAG, "Problem execute put: " + targetURL + " HTTP response: " + responseCode);
        }
        return responseCode + "";
    }

    return responseToString(conn.getInputStream());
}
 
开发者ID:nextgis,项目名称:android_nextgis_mobile,代码行数:37,代码来源:NetworkUtil.java

示例9: save

import java.io.BufferedWriter; //导入方法依赖的package包/类
public void save() throws IOException {
	File usersFile = new File(Constants.LOCATION + "users.lib");
	File collectionFile = new File(Constants.LOCATION + "collection.lib");
       BufferedWriter writeUsers = new BufferedWriter(new FileWriter(usersFile));   
       BufferedWriter writeCollection = new BufferedWriter(new FileWriter(collectionFile));         
       for (Book book : collection.values()){
       	writeCollection.write(book.saveData() + "\n");
       }
       for (User user : users.values()){
       	writeUsers.write(user.saveData() + "\n");
       }
       writeUsers.close();
       writeCollection.close();
}
 
开发者ID:Swipefly,项目名称:koinonia-library,代码行数:15,代码来源:Library.java

示例10: createFile

import java.io.BufferedWriter; //导入方法依赖的package包/类
private void createFile(String content) throws Exception
{
    file = File.createTempFile("RenameUserTest", ".txt");
    args[4] = "-file";
    args[5] = file.getPath();

    BufferedWriter out = new BufferedWriter(new FileWriter(file));
    out.write(content);
    out.close();
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:11,代码来源:RenameUserTest.java

示例11: writingParContent

import java.io.BufferedWriter; //导入方法依赖的package包/类
private static void writingParContent(BufferedWriter wrobj, List<ParContent> parContents) throws IOException {
	for (ParContent parContentPar : parContents) {
		
		if (parContentPar.getClass().getName() == "org.emed.classes.Par") {
			Par par = (Par) parContentPar;
			wrobj.write(par.getContent());
		} else if (parContentPar.getClass().getName() == "org.emed.classes.Italic") {
			Italic italic = (Italic) parContentPar;
			wrobj.write("\\textit{" + italic.getContent() + "}");
		} else if (parContentPar.getClass().getName() == "org.emed.classes.Bold") {
			Bold bold = (Bold) parContentPar;
			wrobj.write("\\textbf{" + bold.getContent() + "}");
	    } else if (parContentPar.getClass().getName() == "org.emed.classes.Xref") {
			Xref xref = (Xref) parContentPar;
			
			if (xref.getBibContent() != null) {
			    wrobj.write("\\cite{bib" + xref.getBibContent() + "}");
			} else if (xref.getFigContent() != null) {   
				wrobj.write(xref.getFigDescription() + " " + xref.getFigContent());
			} else if (xref.getTableContent() != null) {
				wrobj.write(xref.getTableDescription() + " " + xref.getTableContent());
			}
			
			
		} 
			
	} // end of Paragraph content
}
 
开发者ID:Vitaliy-1,项目名称:JATS2LaTeX,代码行数:29,代码来源:BodyGost.java

示例12: SendFileContents

import java.io.BufferedWriter; //导入方法依赖的package包/类
private int SendFileContents(BufferedWriter out, File file) throws IOException {
    int lineNum = 0;
    try (BufferedReader br = new BufferedReader(new FileReader(file))) {
        String line;
        while ((line = br.readLine()) != null) {
            if (line.equals(""))
                break;
            lineNum++;
            out.write(line);
            out.newLine();
        }
    }
    return lineNum;
}
 
开发者ID:ekalyvio,项目名称:CowBit,代码行数:15,代码来源:StepsDataStorage.java

示例13: writeErrorCode

import java.io.BufferedWriter; //导入方法依赖的package包/类
protected static final void writeErrorCode(File resultFile, int exitCode) {
	try {
		BufferedWriter resultFileWriter = new BufferedWriter(new FileWriter(resultFile, true));
		if (exitCode == Miner.STATUS_OOT) {
			resultFileWriter.write("#OOT");
		} else if (exitCode == Miner.STATUS_OOM) {
			resultFileWriter.write("#OOM");
		}
		resultFileWriter.close();
	} catch (IOException e) {
		System.out.println("Couldn't write meta data.");
	}
}
 
开发者ID:HPI-Information-Systems,项目名称:metanome-algorithms,代码行数:14,代码来源:Benchmarker.java

示例14: writeOutputSuccessful

import java.io.BufferedWriter; //导入方法依赖的package包/类
private void writeOutputSuccessful(String outputFile, long time, String inputFileName) {
	String timeString = (time != -1)? String.format("%.1f", (double)(time)/1000) : "-1";
	
	StringBuilder outputBuilder = new StringBuilder();
	if (!inputFileName.isEmpty()) {
		outputBuilder.append(String.format("%s\t", inputFileName));
	}
	outputBuilder.append(String.format("%d\t", this.numberOfRows));
	outputBuilder.append(String.format("%d\t", this.numberOfColumns));
	outputBuilder.append(String.format("%s\t", timeString));
	outputBuilder.append(String.format("%d\t", this.minimalDependencies.getCount()));
	outputBuilder.append(String.format("%d\t", this.minimalDependencies.getCountForSizeLesserThan(2)));
	outputBuilder.append(String.format("%d\t", this.minimalDependencies.getCountForSizeLesserThan(3)));
	outputBuilder.append(String.format("%d\t", this.minimalDependencies.getCountForSizeLesserThan(4)));
	outputBuilder.append(String.format("%d\t", this.minimalDependencies.getCountForSizeLesserThan(5)));
	outputBuilder.append(String.format("%d\t", this.minimalDependencies.getCountForSizeLesserThan(6)));
	outputBuilder.append(String.format("%d\t", this.minimalDependencies.getCountForSizeGreaterThan(5)));
	outputBuilder.append(String.format("%d\t", this.strippedPartitions.size()));
	outputBuilder.append(String.format("%d\t", this.strippedPartitions.size()));
	outputBuilder.append(String.format("%d\n", Runtime.getRuntime().totalMemory()));
	outputBuilder.append(String.format("#Memory: %s\n", Miner.humanReadableByteCount(Runtime.getRuntime().totalMemory(), false)));

	try {
		BufferedWriter resultFileWriter = new BufferedWriter(new FileWriter(new File(outputFile), true));
		resultFileWriter.write(outputBuilder.toString());
		System.out.print(outputBuilder.toString());
		resultFileWriter.close();
	} catch (IOException e) {
		System.out.println("Couldn't write output.");
	}
}
 
开发者ID:HPI-Information-Systems,项目名称:metanome-algorithms,代码行数:32,代码来源:Tane.java

示例15: testPossiblyCompressedDecompressedStreams

import java.io.BufferedWriter; //导入方法依赖的package包/类
/**
 * Test 
 * {@link CompressionEmulationUtil#getPossiblyDecompressedInputStream(Path, 
 *                                   Configuration, long)}
 *  and
 *  {@link CompressionEmulationUtil#getPossiblyCompressedOutputStream(Path, 
 *                                    Configuration)}.
 */
@Test
public void testPossiblyCompressedDecompressedStreams() throws IOException {
  JobConf conf = new JobConf();
  FileSystem lfs = FileSystem.getLocal(conf);
  String inputLine = "Hi Hello!";

  CompressionEmulationUtil.setCompressionEmulationEnabled(conf, true);
  CompressionEmulationUtil.setInputCompressionEmulationEnabled(conf, true);
  conf.setBoolean(FileOutputFormat.COMPRESS, true);
  conf.setClass(FileOutputFormat.COMPRESS_CODEC, GzipCodec.class, 
                CompressionCodec.class);

  // define the test's root temp directory
  Path rootTempDir =
      new Path(System.getProperty("test.build.data", "/tmp")).makeQualified(
          lfs.getUri(), lfs.getWorkingDirectory());

  Path tempDir =
    new Path(rootTempDir, "TestPossiblyCompressedDecompressedStreams");
  lfs.delete(tempDir, true);

  // create a compressed file
  Path compressedFile = new Path(tempDir, "test");
  OutputStream out = 
    CompressionEmulationUtil.getPossiblyCompressedOutputStream(compressedFile, 
                                                               conf);
  BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
  writer.write(inputLine);
  writer.close();
  
  // now read back the data from the compressed stream
  compressedFile = compressedFile.suffix(".gz");
  InputStream in = 
    CompressionEmulationUtil
      .getPossiblyDecompressedInputStream(compressedFile, conf, 0);
  BufferedReader reader = new BufferedReader(new InputStreamReader(in));
  String readLine = reader.readLine();
  assertEquals("Compression/Decompression error", inputLine, readLine);
  reader.close();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:49,代码来源:TestCompressionEmulationUtils.java


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