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


Java BufferedWriter类代码示例

本文整理汇总了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();
  
}
 
开发者ID:Alexandre-Bartel,项目名称:permission-map,代码行数:25,代码来源:OutputGraph.java

示例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();
    }
}
 
开发者ID:zwmlibs,项目名称:BookReader-master,代码行数:26,代码来源:LogUtils.java

示例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;
}
 
开发者ID:pashkobohdan,项目名称:FastReading,代码行数:25,代码来源:FileReadingAndWriting.java

示例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");
    }
}
 
开发者ID:pre-dem,项目名称:pre-dem-android,代码行数:25,代码来源:LogUtils.java

示例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;
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:25,代码来源:CacheManager.java

示例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();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:FSNamesystem.java

示例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;
}
 
开发者ID:priester,项目名称:hanlpStudy,代码行数:17,代码来源:TMDictionaryMaker.java

示例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
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:27,代码来源:DocumentStaxUtils.java

示例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);
  }
}
 
开发者ID:penghongru,项目名称:Coder,代码行数:40,代码来源:DiskLruCache.java

示例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)");
}
 
开发者ID:radsimu,项目名称:UaicNlpToolkit,代码行数:36,代码来源:PrecompileFromDexOnlineDB.java

示例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);
    }
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:26,代码来源:CasRestAuthenticator.java

示例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();
}
 
开发者ID:nasa,项目名称:OpenVSP3Plugin,代码行数:17,代码来源:OpenVSP3Plugin.java

示例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);
        }
    });
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:21,代码来源:JavadocOptionFileWriter.java

示例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);
    }
}
 
开发者ID:wade-fs,项目名称:Military-North-Compass,代码行数:21,代码来源:Compass.java

示例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();
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:17,代码来源:ResultParser2.java


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