本文整理匯總了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;
}
示例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();
}
}
示例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();
}
示例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();
}
}
示例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;
}
示例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();
}
示例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();
}
示例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);
}
}
示例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();
}
}
示例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) {}
}
示例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();
}
}
示例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();
}
示例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();
}
示例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();
}
}
示例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();
}
}
}