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


Java BufferedWriter.close方法代码示例

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


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

示例1: writeFile

import java.io.BufferedWriter; //导入方法依赖的package包/类
/**
* write cofiguration
* @return
* @throws IOException
*/
 private File writeFile() throws IOException {

   File f = new File(testDir, "tst.xml");
   BufferedWriter out = new BufferedWriter(new FileWriter(f));
   String properties = "<properties><property key=\"key\" value=\"value\"/><property key=\"key1\" value=\"value1\"/></properties>";
   out.write("<queues>");
   out.newLine();
   out.write("<queue><name>first</name><acl-submit-job>user1,user2 group1,group2</acl-submit-job><acl-administer-jobs>user3,user4 group3,group4</acl-administer-jobs><state>running</state></queue>");
   out.newLine();
   out.write("<queue><name>second</name><acl-submit-job>u1,u2 g1,g2</acl-submit-job>"
       + properties + "<state>stopped</state></queue>");
   out.newLine();
   out.write("</queues>");
   out.flush();
   out.close();
   return f;

 }
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:TestQueue.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,代码来源:hUpperMerge.java

示例3: createInputFile

import java.io.BufferedWriter; //导入方法依赖的package包/类
/**
 * Create a single input file in the input directory.
 * @param dirPath the directory in which the file resides
 * @param id the file id number
 * @param numRecords how many records to write to each file.
 */
private void createInputFile(Path dirPath, int id, int numRecords)
    throws IOException {
  final String MESSAGE = "This is a line in a file: ";

  Path filePath = new Path(dirPath, "" + id);
  Configuration conf = new Configuration();
  FileSystem fs = FileSystem.getLocal(conf);

  OutputStream os = fs.create(filePath);
  BufferedWriter w = new BufferedWriter(new OutputStreamWriter(os));

  for (int i = 0; i < numRecords; i++) {
    w.write(MESSAGE + id + " " + i + "\n");
  }

  w.close();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:TestLocalRunner.java

示例4: 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:wp521,项目名称:MyFire,代码行数:26,代码来源:LogUtils.java

示例5: generateConfigFile

import java.io.BufferedWriter; //导入方法依赖的package包/类
public String generateConfigFile(boolean noOutput) throws IOException
{
	String _configName = "config" + _counter + ".txt";
	_outDir = "out" + _counter;
	_counter++;
	
	BufferedWriter configWriter = new BufferedWriter(new FileWriter(_configPath + _configName));

	generatePreambleAndOutputPaths(configWriter);
	generateScenarioRepetitions(configWriter);
	generateParameters(configWriter);
	generateDeviations(configWriter);
	generateRandomsAndMappingLang(configWriter);
	generateOutputActivation(configWriter, noOutput);
	generateTrampOutputActivation(configWriter);

	configWriter.close();
	
	return _configName;
}
 
开发者ID:RJMillerLab,项目名称:ibench,代码行数:21,代码来源:ConfigGenerator.java

示例6: modifyCSVFile

import java.io.BufferedWriter; //导入方法依赖的package包/类
public void modifyCSVFile(File csvFile,File shiftedCSVFile,double shift) throws IOException{
	
	if (!csvFile.exists()) {
		throw new IllegalArgumentException("File '" + csvFile + "' does not exist");
	}
	
	FileReader fileReader = new FileReader(csvFile);
	BufferedReader in = new BufferedReader(fileReader);
	
	FileWriter fileWriter = new FileWriter(shiftedCSVFile);
	BufferedWriter out = new BufferedWriter(fileWriter);
	
	String inputLine = in.readLine();	
	while (inputLine != null) {
		final String[] row = inputLine.split(",");
		if (!inputLine.trim().isEmpty() && row.length > 1) {
			double timeInSeconds = Double.valueOf(row[0]);
			double shiftedTime = timeInSeconds + shift;
			String outputLine = String.format("%.4f" , shiftedTime)  + inputLine.substring(row[0].length(), inputLine.length()) + System.lineSeparator();
			out.write(outputLine);
		}
		inputLine = in.readLine();
	}
	out.close();
	in.close();
}
 
开发者ID:JorenSix,项目名称:Panako,代码行数:27,代码来源:SyncSinkFrame.java

示例7: dumpExamplesLibSvm

import java.io.BufferedWriter; //导入方法依赖的package包/类
public void dumpExamplesLibSvm(String filename, FeatureNormalizer fn, int[] selectedFeatures) throws IOException {
	BufferedWriter wr = new BufferedWriter(new FileWriter(filename, false));

	for (int i = 0; i < featureVectorsAndTargetGroups.size(); i++){
		List<String> vectors = new Vector<String>();
		
		for (Pair<FeaturePack<T>, Double> vectAndGold : featureVectorsAndTargetGroups.get(i))
			vectors.add(writeLineLibSvm(fn.ftrToNormalizedFtrArray(vectAndGold.first), wr, vectAndGold.second, i, selectedFeatures));

		//This is just to make sure that lines are output always in the same order. (It seems that vector order does change the resulting model with some libraries.)
		Collections.sort(vectors);
		
		for (String vectorLine: vectors){
			wr.write(vectorLine);
			wr.write("\n");
		}
	}			
	wr.close();
}
 
开发者ID:marcocor,项目名称:smaph,代码行数:20,代码来源:ExampleGatherer.java

示例8: createTextFile

import java.io.BufferedWriter; //导入方法依赖的package包/类
/**
 * Create a data file that gets exported to the db.
 * @param fileNum the number of the file (for multi-file export)
 * @param numRecords how many records to write to the file.
 * @param gzip is true if the file should be gzipped.
 */
protected void createTextFile(int fileNum, int numRecords, boolean gzip,
    ColumnGenerator... extraCols) throws IOException {
  int startId = fileNum * numRecords;

  String ext = ".txt";
  if (gzip) {
    ext = ext + ".gz";
  }
  Path tablePath = getTablePath();
  Path filePath = new Path(tablePath, "part" + fileNum + ext);

  Configuration conf = new Configuration();
  if (!BaseSqoopTestCase.isOnPhysicalCluster()) {
    conf.set(CommonArgs.FS_DEFAULT_NAME, CommonArgs.LOCAL_FS);
  }
  FileSystem fs = FileSystem.get(conf);
  fs.mkdirs(tablePath);
  OutputStream os = fs.create(filePath);
  if (gzip) {
    CompressionCodecFactory ccf = new CompressionCodecFactory(conf);
    CompressionCodec codec = ccf.getCodec(filePath);
    os = codec.createOutputStream(os);
  }
  BufferedWriter w = new BufferedWriter(new OutputStreamWriter(os));
  for (int i = 0; i < numRecords; i++) {
    w.write(getRecordLine(startId + i, extraCols));
  }
  w.close();
  os.close();

  if (gzip) {
    verifyCompressedFile(filePath, numRecords);
  }
}
 
开发者ID:aliyun,项目名称:aliyun-maxcompute-data-collectors,代码行数:41,代码来源:TestExport.java

示例9: forceWriteToFile

import java.io.BufferedWriter; //导入方法依赖的package包/类
private static synchronized void forceWriteToFile(String string) {

        try {
            FileWriter fstream = new FileWriter(Environment.getExternalStorageDirectory() + File.separator + sFileName, true);
            BufferedWriter fbw = new BufferedWriter(fstream);
            fbw.write("\n\n" + string);
            fbw.newLine();
            fbw.close();
        } catch (Throwable e) {
            e.printStackTrace();
        }

    }
 
开发者ID:yajnesh,项目名称:AndroidGeneralUtils,代码行数:14,代码来源:BLog.java

示例10: saveWaypoints

import java.io.BufferedWriter; //导入方法依赖的package包/类
public void saveWaypoints()
{
	try
	{
		File file = new File(xdolfDir.getAbsolutePath(), "waypoints.txt");
		BufferedWriter out = new BufferedWriter(new FileWriter(file));
		for(Waypoint wayPoint : Waypoint.wayPoints)
		{
			out.write(wayPoint.getName() + ":" + (int)wayPoint.getX() + ":" + (int)wayPoint.getY() + ":" + (int)wayPoint.getZ());
			out.write("\r\n");
		}
		out.close();
	}catch(Exception e) {}
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:15,代码来源:FileManager.java

示例11: writeTxtFile

import java.io.BufferedWriter; //导入方法依赖的package包/类
private static void writeTxtFile( File outputDir ) {
	String MSGFBatFilePath = outputDir.toString() + "\\WiffToMzxmlcmds.txt";
	try {
		BufferedWriter bufwriter = new BufferedWriter( new FileWriter(MSGFBatFilePath) );
		bufwriter.write(WiffMzmlBatFile.toString());
		bufwriter.close();
	} catch( Exception e ) {
		e.printStackTrace();
	}
}
 
开发者ID:jgmeyerucsd,项目名称:PIQEDia,代码行数:11,代码来源:CreateWiffToMzxmlmp.java

示例12: writeLineSeparator

import java.io.BufferedWriter; //导入方法依赖的package包/类
static void writeLineSeparator(Path p,
                               IntFunction<LineSeparator> lineSeparatorGenerator,
                               int lines, Charset cs) throws IOException {
    BufferedWriter bw = Files.newBufferedWriter(p, cs, StandardOpenOption.APPEND);
    bw.write(lineSeparatorGenerator.apply(lines - 1).value);
    bw.flush();
    bw.close();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:StreamLinesTest.java

示例13: testDumpPeople2014ToBEMS

import java.io.BufferedWriter; //导入方法依赖的package包/类
public void testDumpPeople2014ToBEMS() throws Exception
{
    final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("D:\\Tools\\CRF++-0.58\\example\\seg_cn\\2014.txt")));
    CorpusLoader.walk("D:\\JavaProjects\\CorpusToolBox\\data\\2014", new CorpusLoader.Handler()
    {
        @Override
        public void handle(Document document)
        {
            List<List<Word>> simpleSentenceList = document.getSimpleSentenceList();
            for (List<Word> wordList : simpleSentenceList)
            {
                try
                {
                    for (Word word : wordList)
                    {

                        bw.write(word.value);
                        bw.write(' ');

                    }
                    bw.newLine();
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
        }
    });
    bw.close();
}
 
开发者ID:priester,项目名称:hanlpStudy,代码行数:32,代码来源:TestICWB.java

示例14: writeIntoFile

import java.io.BufferedWriter; //导入方法依赖的package包/类
public static void writeIntoFile(File file ,  String text , String charset){
    try {
        FileOutputStream outputStream = new FileOutputStream(file);
        OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, charset);
        BufferedWriter bufferWritter = new BufferedWriter(outputStreamWriter);
        bufferWritter.write(text);
        bufferWritter.close();
        outputStreamWriter.close();
        outputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:bbedword,项目名称:AutoDnaCode,代码行数:14,代码来源:AutoCodeUtil.java

示例15: doZoomHistory

import java.io.BufferedWriter; //导入方法依赖的package包/类
protected void doZoomHistory(String past, String next) throws IOException {

		if (app instanceof MapApp) {
			if(((MapApp) app).historyFile.exists()) {
				((MapApp) app).startNewZoomHistory();
			}

			if(((MapApp) app).historyFile.canWrite()) {
				BufferedWriter bw = new BufferedWriter(new FileWriter(((MapApp) app).historyFile.getAbsoluteFile(), false));
				bw.write(past + "\n");
				bw.write(next);
				bw.close();
			}
		}
	}
 
开发者ID:iedadata,项目名称:geomapapp,代码行数:16,代码来源:XMap.java


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