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