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


Java BufferedWriter.flush方法代码示例

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


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

示例1: 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:Evan-Galvin,项目名称:FreeStreams-TVLauncher,代码行数:24,代码来源:LogUtil.java

示例2: storeTimeStamps

import java.io.BufferedWriter; //导入方法依赖的package包/类
private void storeTimeStamps() throws IOException {
    final File f = new File (cacheRoot, TIME_STAMPS);
    if (timeStamps == null) {
        f.delete();
    } else {
        timeStamps.first().keySet().removeAll(timeStamps.second());
        final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f), "UTF-8")); //NOI18N
        try {
            // write data
            for(LongHashMap.Entry<String> entry : timeStamps.first().entrySet()) {
                out.write(entry.getKey());
                out.write('='); //NOI18N
                out.write(Long.toString(entry.getValue()));
                out.newLine();
            }
            out.flush();
        } finally {
            timeStamps = null;
            out.close();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:BinaryAnalyser.java

示例3: zipFile

import java.io.BufferedWriter; //导入方法依赖的package包/类
@Override
protected void zipFile(File file, ZipOutputStream zOut, String vPath, int mode) throws IOException {
    if (vPath.equals(layer)) {
        System.setProperty("CslJar", Boolean.TRUE.toString());
        try {
            // Create a tempfile and trick it!
            InputStream is = new FileInputStream(file);
            String modifiedLayer = getModifiedLayer(is);
            if (modifiedLayer != null) {
                File tmpFile = File.createTempFile("csl", "tmp"); // NOI18N
                BufferedWriter w = new BufferedWriter(new FileWriter(tmpFile));
                w.write(modifiedLayer);
                w.flush();
                w.close();
                // Note - we're passing the temp file instead of the "real" layer file
                super.zipFile(tmpFile, zOut, vPath, mode);
                // Remove the tmpfile
                tmpFile.delete();
                return;
            }
        } finally {
            System.setProperty("CslJar", Boolean.FALSE.toString());
        }
    }
    super.zipFile(file, zOut, vPath, mode);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:CslJar.java

示例4: store

import java.io.BufferedWriter; //导入方法依赖的package包/类
/**
 * Store properties to a stream.
 * @param stream an output stream
 * @throws IOException if the stream could not be written to
 */
public void store(OutputStream stream) throws IOException {
    boolean previousLineWasEmpty = true;
    BufferedWriter output = new BufferedWriter(new OutputStreamWriter(stream, "ISO-8859-1"));
    for (Item item : state.items) {
        if (item.isSeparate() && !previousLineWasEmpty) {
            output.newLine();
        }
        String line = null;
        Iterator<String> it = item.getRawData().iterator();
        while (it.hasNext()) {
            line = it.next();
            output.write(line);
            output.newLine();
        }
        if (line != null) {
            previousLineWasEmpty = isEmpty(line);
        }
    }
    output.flush();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:EditableProperties.java

示例5: 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

示例6: writeTo

import java.io.BufferedWriter; //导入方法依赖的package包/类
public void writeTo(BufferedWriter bw, InfoTable it) throws IOException {
    bw.write("RegNr:"+it.getRegNr());
    bw.newLine();
    bw.write("ZuNr:"+it.getZuNr());
    ArrayList<String> names = it.getNames();
    ArrayList<String> infos = it.getInfos();
    for(int i = 0; i < it.getRowCount(); i++) {
        bw.newLine();
        bw.write(names.get(i) + infos.get(i));
    }
    bw.flush();
    bw.close();
}
 
开发者ID:froehlichA,项目名称:RA-Reader,代码行数:14,代码来源:WriteToFile.java

示例7: write

import java.io.BufferedWriter; //导入方法依赖的package包/类
@ApiMethod
public static void write(File file, String text) throws Exception
{
   if (!file.exists())
      file.getParentFile().mkdirs();

   BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "UTF-8"));
   bw.write(text);
   bw.flush();
   bw.close();
}
 
开发者ID:wellsb1,项目名称:fort_j,代码行数:12,代码来源:Files.java

示例8: 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,项目名称:Wilmersdorf_SER316,代码行数:19,代码来源:LoadableProperties.java

示例9: generateSitemap

import java.io.BufferedWriter; //导入方法依赖的package包/类
/**
 * Performs the generation of the sitemap.xml file.
 */
public void generateSitemap() {
    List<String> urls = getSitemapUrls();

    try {
        File outputDir = new File(targetDir);
        if (!outputDir.exists()) {
            outputDir.mkdirs();
        }

        File outputFile = new File(outputDir, "sitemap.xml");

        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile),"UTF8"));
        
        out.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
        out.write("<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n");                 

        Iterator<String> urlsIterator = urls.listIterator();
        while (urlsIterator.hasNext()) {
            out.write(urlsIterator.next());
        }

        out.write(getSitemapUrl(loc + DEFAULT_PAGE_PATH));
        out.write("</urlset>");

        out.flush();
        out.close();
    }
    catch (Exception exc) {
        exc.printStackTrace();
    }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:35,代码来源:SitemapGenerator.java

示例10: createImage

import java.io.BufferedWriter; //导入方法依赖的package包/类
/**
 * 绘制词云图片
 * @param savePicPath 图片存储路径
 * @param picWidth 图片宽度
 * @param picHeight 图片高度
 * @param blackBackground 是否使用黑色背景
 * @throws IOException
 */
public void createImage(String savePicPath, int picWidth, int picHeight, boolean blackBackground) throws IOException {
    String tempFileName = UUID.randomUUID().toString();
    // 生成临时词语文件
    BufferedWriter bw = new BufferedWriter(new FileWriter("word_cloud/" + tempFileName));
    for (String word : wordList)
        bw.write(word + "\n");
    bw.flush();
    bw.close();
    StringBuilder cmd = new StringBuilder(Config.pythonCMD());
    cmd.append(" create_word_cloud.py");
    cmd.append(" -l ");
    cmd.append(tempFileName);
    cmd.append(" -w ");
    cmd.append(picWidth);
    cmd.append(" -h ");
    cmd.append(picHeight);
    cmd.append(" -b ");
    cmd.append(blackBackground ? "black" : "white");
    cmd.append(" -s ");
    cmd.append("\"" + savePicPath + "\"");
    cmd.append(" -f ");
    cmd.append("\"simhei.ttf\"");
    System.out.println(cmd.toString());
    Process pr = Runtime.getRuntime().exec(cmd.toString(), null, new File("word_cloud/"));
    try {
        pr.waitFor();
    } catch (InterruptedException e) {
        e.printStackTrace();
    } finally {
        pr.destroy();
    }
    new File("word_cloud/" + tempFileName).delete();
    System.out.println("create wordcloud success!");
}
 
开发者ID:jsksxs360,项目名称:AHANLP,代码行数:43,代码来源:WordCloud.java

示例11: doPostRequest

import java.io.BufferedWriter; //导入方法依赖的package包/类
private void doPostRequest(String destination, String parms) throws IOException {
    URL url = new URL(destination);
    String response = "";
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    conn.setReadTimeout(10000);
    conn.setConnectTimeout(15000);
    conn.setRequestMethod("POST");
    conn.setDoInput(true);
    conn.setDoOutput(true);

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

    conn.connect();
    int responseCode = conn.getResponseCode();

    if (responseCode == HttpURLConnection.HTTP_OK) {
        String line;
        BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream()));
        while ((line=br.readLine()) != null) {
            response+=line;
        }
    }
    else {
        response="";

    }
}
 
开发者ID:jsparber,项目名称:CaptivePortalAutologin,代码行数:34,代码来源:CaptivePortalLoginActivity.java

示例12: saveConfig

import java.io.BufferedWriter; //导入方法依赖的package包/类
private void saveConfig(BufferedWriter bufferedWriter) {
    boolean line_spe = false;
    try {
        if (this.line_separator == null || this.line_separator.trim().equals("")) {
            line_spe = false;
        }
        for (Section section : this.sections.values()) {
            if (!(section.getName().equals("") || section.getName() == null)) {
                bufferedWriter.write("[" + section.getName() + "]");
                if (line_spe) {
                    bufferedWriter.write(this.line_separator);
                } else {
                    bufferedWriter.newLine();
                }
            }
            for (Entry<String, Object> entry : section.getValues().entrySet()) {
                bufferedWriter.write((String) entry.getKey());
                bufferedWriter.write(SearchCriteria.EQ);
                bufferedWriter.write(entry.getValue().toString());
                if (line_spe) {
                    bufferedWriter.write(this.line_separator);
                } else {
                    bufferedWriter.newLine();
                }
            }
        }
        bufferedWriter.flush();
        bufferedWriter.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:33,代码来源:IniFile.java

示例13: closeWriters

import java.io.BufferedWriter; //导入方法依赖的package包/类
public void closeWriters() {
	try {
		for (BufferedWriter writer : writers) {
			writer.flush();
			writer.close();
		}
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
开发者ID:mulinlab,项目名称:vanno,代码行数:12,代码来源:RunConfigBean.java

示例14: save

import java.io.BufferedWriter; //导入方法依赖的package包/类
public void save(OutputStream outStream) throws IOException {
    BufferedWriter out = new BufferedWriter(new OutputStreamWriter(outStream, "UTF-8"));
    String aKey;
    Object aValue;
    for (Enumeration e = keys(); e.hasMoreElements();) {
        aKey = (String) e.nextElement();
        aValue = get(aKey);
        out.write(aKey + " = " + aValue);
        out.newLine();
    }
    out.flush();
    out.close();
}
 
开发者ID:ser316asu,项目名称:SER316-Munich,代码行数:14,代码来源:LoadableProperties.java

示例15: writeLongToFile

import java.io.BufferedWriter; //导入方法依赖的package包/类
static void writeLongToFile(File file, long value) throws IOException {
    AtomicFileOutputStream out = new AtomicFileOutputStream(file);
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
    try {
        bw.write(Long.toString(value));
        bw.flush();
        out.flush();
        out.close();
    } catch (IOException e) {
        LOG.error("Failed to write new file " + file, e);
        out.abort();
        throw e;
    }
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:15,代码来源:QuorumPeerMainTest.java


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