本文整理匯總了Java中java.io.BufferedWriter類的典型用法代碼示例。如果您正苦於以下問題:Java BufferedWriter類的具體用法?Java BufferedWriter怎麽用?Java BufferedWriter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BufferedWriter類屬於java.io包,在下文中一共展示了BufferedWriter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: generateCSV
import java.io.BufferedWriter; //導入依賴的package包/類
/**
* Generate file representing the graph as comma separated edges.
* @param outputName
* @throws IOException
*/
public void generateCSV(String outputName) throws IOException {
// create directory to write graphs
File graphDir = new File(Options.v().output_dir() +"/"+ "graphs/");
if (!graphDir.exists())
graphDir.mkdir();
for (int i=0; i < ConfigCHA.v().getGraphOutMaxDepth(); i++) {
String name = graphDir.getAbsolutePath() +"/"+ i + outputName;
out.add(new PrintWriter(new BufferedWriter(new FileWriter(name))));
log.info("Output CSV graph to '"+ name);
}
Set<SootMethod> alreadyVisited = new HashSet<SootMethod>();
SootMethod main = Scene.v().getMainMethod();
alreadyVisited.add(main);
visit(alreadyVisited, main, 0);
for (int i=0; i < ConfigCHA.v().getGraphOutMaxDepth(); i++)
out.get(i).close();
}
示例2: log2File
import java.io.BufferedWriter; //導入依賴的package包/類
/**
* 打開日誌文件並寫入日誌
*
* @return
**/
private synchronized static void log2File(String mylogtype, String tag, String text) {
Date nowtime = new Date();
String date = FILE_SUFFIX.format(nowtime);
String dateLogContent = LOG_FORMAT.format(nowtime) + ":" + mylogtype + ":" + tag + ":" + text; // 日誌輸出格式
File destDir = new File(LOG_FILE_PATH);
if (!destDir.exists()) {
destDir.mkdirs();
}
File file = new File(LOG_FILE_PATH, LOG_FILE_NAME + date);
try {
FileWriter filerWriter = new FileWriter(file, true);
BufferedWriter bufWriter = new BufferedWriter(filerWriter);
bufWriter.write(dateLogContent);
bufWriter.newLine();
bufWriter.close();
filerWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例3: 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;
}
示例4: writeLog
import java.io.BufferedWriter; //導入依賴的package包/類
/**
* 打印信息
*
* @param message
*/
public static synchronized void writeLog(String message) {
File f = getFile();
if (f != null) {
try {
FileWriter fw = new FileWriter(f, true);
BufferedWriter bw = new BufferedWriter(fw);
bw.append("\n");
bw.append(message);
bw.append("\n");
bw.flush();
bw.close();
fw.close();
} catch (IOException e) {
print("writeLog error, " + e.getMessage());
}
} else {
print("writeLog error, due to the file dir is error");
}
}
示例5: create
import java.io.BufferedWriter; //導入依賴的package包/類
public Path create() {
try {
if (Files.exists(path)) {
List<String> otherKeys;
try (Stream<String> stream = Files.lines(getMetadataFile(), StandardCharsets.UTF_8)) {
otherKeys = stream.collect(Collectors.toList());
}
if (!keys.equals(otherKeys)) {
throw new PowsyblException("Inconsistent cache hash code");
}
} else {
Files.createDirectories(path);
try (BufferedWriter writer = Files.newBufferedWriter(getMetadataFile(), StandardCharsets.UTF_8)) {
for (String key : keys) {
writer.write(key);
writer.newLine();
}
}
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return path;
}
示例6: metaSave
import java.io.BufferedWriter; //導入依賴的package包/類
/**
* Dump all metadata into specified file
*/
void metaSave(String filename) throws IOException {
checkSuperuserPrivilege();
checkOperation(OperationCategory.UNCHECKED);
writeLock();
try {
checkOperation(OperationCategory.UNCHECKED);
File file = new File(System.getProperty("hadoop.log.dir"), filename);
PrintWriter out = new PrintWriter(new BufferedWriter(
new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8)));
metaSave(out);
out.flush();
out.close();
} finally {
writeUnlock();
}
}
示例7: saveTxtTo
import java.io.BufferedWriter; //導入依賴的package包/類
@Override
public boolean saveTxtTo(String path)
{
try
{
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(IOUtil.newOutputStream(path)));
bw.write(toString());
bw.close();
}
catch (Exception e)
{
logger.warning("在保存轉移矩陣詞典到" + path + "時發生異常" + e);
return false;
}
return true;
}
示例8: writeXcesContent
import java.io.BufferedWriter; //導入依賴的package包/類
/**
* Save the content of a document to the given output stream. Since
* XCES content files are plain text (not XML), XML-illegal characters
* are not replaced when writing. The stream is <i>not</i> closed by
* this method, that is left to the caller.
*
* @param doc the document to save
* @param out the stream to write to
* @param encoding the character encoding to use. If null, defaults to
* UTF-8
*/
public static void writeXcesContent(Document doc, OutputStream out,
String encoding) throws IOException {
if(encoding == null) {
encoding = "UTF-8";
}
String documentContent = doc.getContent().toString();
OutputStreamWriter osw = new OutputStreamWriter(out, encoding);
BufferedWriter writer = new BufferedWriter(osw);
writer.write(documentContent);
writer.flush();
// do not close the writer, this would close the underlying stream,
// which is something we want to leave to the caller
}
示例9: readJournal
import java.io.BufferedWriter; //導入依賴的package包/類
private void readJournal() throws IOException {
StrictLineReader reader = new StrictLineReader(new FileInputStream(journalFile), DiskUtil.US_ASCII);
try {
String magic = reader.readLine();
String version = reader.readLine();
String appVersionString = reader.readLine();
String valueCountString = reader.readLine();
String blank = reader.readLine();
if (!MAGIC.equals(magic)
|| !VERSION_1.equals(version)
|| !Integer.toString(appVersion).equals(appVersionString)
|| !Integer.toString(valueCount).equals(valueCountString)
|| !"".equals(blank)) {
throw new IOException("unexpected journal header: [" + magic + ", " + version + ", "
+ valueCountString + ", " + blank + "]");
}
int lineCount = 0;
while (true) {
try {
readJournalLine(reader.readLine());
lineCount++;
} catch (EOFException endOfJournal) {
break;
}
}
redundantOpCount = lineCount - lruEntries.size();
// If we ended on a truncated line, rebuild the journal before appending to it.
if (reader.hasUnterminatedLine()) {
rebuildJournal();
} else {
journalWriter = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(journalFile, true), DiskUtil.US_ASCII));
}
} finally {
DiskUtil.closeQuietly(reader);
}
}
示例10: updateReflPronouns
import java.io.BufferedWriter; //導入依賴的package包/類
public static void updateReflPronouns(Connection con) throws SQLException, IOException {
MyDictionary dictionary = new MyDictionary();
Statement stmt = con.createStatement();
long k = 0;
ResultSet rs = stmt.executeQuery("SELECT \n"
+ " inflectedform.formUtf8General as inflForm, \n"
+ " inflectedform.inflectionId as inflId, \n"
+ " lexem.formUtf8General as lemma,\n"
+ " definition.internalRep as definition\n"
+ "FROM inflectedform \n"
+ "JOIN lexemmodel on inflectedform.lexemmodelId=lexemmodel.id \n"
+ "JOIN lexem on lexemmodel.lexemId=lexem.id \n"
+ "JOIN lexemdefinitionmap on lexemdefinitionmap.lexemId=lexem.Id \n"
+ "JOIN definition on definition.id = lexemdefinitionmap.definitionId \n"
+ "WHERE (inflectedform.inflectionId=84 || (inflectedform.inflectionId>40 && inflectedform.inflectionId<49)) AND definition.internalRep LIKE '% #pron\\. refl\\.%' \n"
+ "ORDER BY inflectedform.formUtf8General");
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(MyDictionary.folder + "grabedForUse/" + pronReflFile), "UTF8"));
while (rs.next()) {
MyDictionaryEntry entry = new MyDictionaryEntry(rs.getString("inflForm"), null, null, null);
entry.setLemma(rs.getString("lemma"));
entry.setMsd("Px");
preprocessEntry(entry, rs.getInt("inflId"));
if (!dictionary.contains(entry)) {
out.write(entry.toString() + "\n");
dictionary.Add(entry);
k++;
}
}
stmt.close();
rs.close();
out.close();
System.out.println("Finished reflexive pronouns (" + k + " added)");
}
示例11: requestTicketGrantingTicket
import java.io.BufferedWriter; //導入依賴的package包/類
private String requestTicketGrantingTicket(final String username, final String password) {
HttpURLConnection connection = null;
try {
connection = HttpUtils.openPostConnection(new URL(this.casRestUrl));
final String payload = HttpUtils.encodeQueryParam(Pac4jConstants.USERNAME, username)
+ "&" + HttpUtils.encodeQueryParam(Pac4jConstants.PASSWORD, password);
final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(connection.getOutputStream(), HttpConstants.UTF8_ENCODING));
out.write(payload);
out.close();
final String locationHeader = connection.getHeaderField("location");
final int responseCode = connection.getResponseCode();
if (locationHeader != null && responseCode == HttpConstants.CREATED) {
return locationHeader.substring(locationHeader.lastIndexOf("/") + 1);
}
throw new TechnicalException("Ticket granting ticket request failed: " + locationHeader + " " + responseCode +
HttpUtils.buildHttpErrorMessage(connection));
} catch (final IOException e) {
throw new TechnicalException(e);
} finally {
HttpUtils.closeConnection(connection);
}
}
示例12: writeCompGeomScriptFile
import java.io.BufferedWriter; //導入依賴的package包/類
void writeCompGeomScriptFile(String filename) throws Exception {
LOG.trace("writeCompGeomScriptFile()");
BufferedWriter bw = new BufferedWriter(new FileWriter(tempDir + "\\" + filename));
bw.write("void main()"); bw.newLine();
bw.write("{"); bw.newLine();
bw.write(" SetComputationFileName(COMP_GEOM_TXT_TYPE, \"./OpenVSP3PluginCompGeom.txt\");"); bw.newLine();
bw.write(" SetComputationFileName(COMP_GEOM_CSV_TYPE, \"./OpenVSP3PluginCompGeom.csv\");"); bw.newLine();
bw.write(" ComputeCompGeom(0, false, COMP_GEOM_CSV_TYPE);"); bw.newLine();
bw.write(" while ( GetNumTotalErrors() > 0 )"); bw.newLine();
bw.write(" {"); bw.newLine();
bw.write(" ErrorObj err = PopLastError();"); bw.newLine();
bw.write(" Print( err.GetErrorString() );"); bw.newLine();
bw.write(" }"); bw.newLine();
bw.write("}"); bw.newLine();
bw.close();
}
示例13: write
import java.io.BufferedWriter; //導入依賴的package包/類
void write(File outputFile) throws IOException {
IoActions.writeTextFile(outputFile, new ErroringAction<BufferedWriter>() {
@Override
protected void doExecute(BufferedWriter writer) throws Exception {
final Map<String, JavadocOptionFileOption<?>> options = new TreeMap<String, JavadocOptionFileOption<?>>(optionFile.getOptions());
JavadocOptionFileWriterContext writerContext = new JavadocOptionFileWriterContext(writer);
JavadocOptionFileOption<?> localeOption = options.remove("locale");
if (localeOption != null) {
localeOption.write(writerContext);
}
for (final String option : options.keySet()) {
options.get(option).write(writerContext);
}
optionFile.getSourceNames().write(writerContext);
}
});
}
示例14: save
import java.io.BufferedWriter; //導入依賴的package包/類
private void save() {
File file = new File(Environment.getExternalStorageDirectory()+"/save-compass-1.txt");
try {
FileWriter f = new FileWriter(file);
BufferedWriter bufferedWriter = new BufferedWriter(f);
bufferedWriter.write(
O1X+"\n"+
O1Y+"\n"+
O1A+"\n"+
O2X+"\n"+
O2Y+"\n"+
O2A+"\n"
);
bufferedWriter.flush();
bufferedWriter.close();
f.close();
} catch (IOException e) {
warn("無法儲存資料到 save-compass-1.txt", 0);
}
}
示例15: outputNetTraffic
import java.io.BufferedWriter; //導入依賴的package包/類
private void outputNetTraffic(Map<IndexType, RunStatistics> runStatMap) throws IOException {
BufferedWriter bw = new BufferedWriter(new FileWriter(netTrafficFile));
System.out.println("type\tInsert\tQuery");
bw.write("type\tInsert\tQuery\n");
RunStatistics base = runStatMap.get(IndexType.NoIndex);
for (IndexType indexType : indexTypes) {
RunStatistics stat = runStatMap.get(indexType);
StringBuilder sb = new StringBuilder();
sb.append(indexType).append("\t")
.append(convert(stat.insertNetTraffic / base.insertNetTraffic)).append("\t")
.append(convert(stat.scanNetTraffic / base.scanNetTraffic));
System.out.println(sb.toString());
bw.write(sb.toString() + "\n");
}
bw.close();
}