本文整理汇总了Java中java.io.FileWriter.close方法的典型用法代码示例。如果您正苦于以下问题:Java FileWriter.close方法的具体用法?Java FileWriter.close怎么用?Java FileWriter.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.FileWriter
的用法示例。
在下文中一共展示了FileWriter.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: btnSaveAsActionPerformed
import java.io.FileWriter; //导入方法依赖的package包/类
private void btnSaveAsActionPerformed(ActionEvent paramActionEvent) {
JFileChooser localJFileChooser = new JFileChooser();
localJFileChooser.addChoosableFileFilter(new JavaFileFilter("html", "HTML Files"));
localJFileChooser.addChoosableFileFilter(new JavaFileFilter("doc", "Document Files"));
localJFileChooser.addChoosableFileFilter(new JavaFileFilter("txt", "Text Files"));
int i = localJFileChooser.showSaveDialog(this);
if (i != 0) {
return;
}
String str = localJFileChooser.getSelectedFile().getAbsolutePath();
try {
FileWriter localFileWriter = new FileWriter(str, false);
localFileWriter.write(this.txtSumary.getText());
localFileWriter.close();
} catch (FileNotFoundException localFileNotFoundException) {
localFileNotFoundException.printStackTrace();
return;
} catch (IOException localIOException) {
localIOException.printStackTrace();
return;
}
}
示例2: writeReadTest
import java.io.FileWriter; //导入方法依赖的package包/类
@Test
public void writeReadTest() throws Exception {
LocalEncryptionKeyContainer container = new LocalEncryptionKeyContainer();
container.addKey("a", "b", 1, new byte[] {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
container.addKey("a", "b", 2, new byte[] {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2});
container.addKey("d", 3, new byte[] {3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3});
container.addKey("d", 4, new byte[] {4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4});
File file = folder.newFile();
FileWriter writer = new FileWriter(file);
container.write(writer);
writer.flush();
writer.close();
LocalEncryptionKeyContainer container2 = LocalEncryptionKeyContainer.read(new FileReader(file));
assertThat("has matching keys", container2.getAttributeKey("a", "b", 1, 16), equalTo(container.getAttributeKey("a", "b", 1, 16)));
assertThat("has matching keys", container2.getAttributeKey("a", "b", 2, 16), equalTo(container.getAttributeKey("a", "b", 2, 16)));
assertThat("has matching keys", container2.getKey("d", 3, 16), equalTo(container.getKey("d", 3, 16)));
assertThat("has matching keys", container2.getKey("d", 4, 16), equalTo(container.getKey("d", 4, 16)));
}
示例3: main
import java.io.FileWriter; //导入方法依赖的package包/类
public static void main(String[] args) {
int size = 100;
creatStr(size, size);
createFile(size);
createDir(size);
createRoot();
createContents(size, size);
str += "\n\ncontents in Dir -> (Dir + File)\n" + "all d:Dir | not (d in d.^contents)\n"
+ "Root in Dir\n" + "(File + Dir) in Root.*contents";
System.out.println(str);
File tempFile = new File(
"./../eu.modelwriter.traceability.validation.core.crocopat/files/KodKodTestFile.kodkod");
try {
FileWriter fileWriter = new FileWriter(tempFile);
fileWriter.write(str);
fileWriter.flush();
fileWriter.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例4: process
import java.io.FileWriter; //导入方法依赖的package包/类
public void process(File pdf, File output){
PDDocument pdDoc;
try {//Kudos for closing: http://stackoverflow.com/questions/156508/closing-a-java-fileinputstream
File tmpfile = File.createTempFile(String.format("txttmp-%s", UUID.randomUUID().toString()), null);
RandomAccessFile raf = new RandomAccessFile(tmpfile, "rw");
pdDoc = PDDocument.loadNonSeq(pdf, raf);
FileWriter writer = new FileWriter(output);
try {
PDFTextStripper stripper = new PDFTextStripper();
int numberOfPages = pdDoc.getNumberOfPages();
for (int j = 1; j < numberOfPages+1; j++) {
stripper.setStartPage(j);
stripper.setEndPage(j);
writer.write(stripper.getText(pdDoc));
writer.flush();
}
} finally {
pdDoc.close();
raf.close();
tmpfile.delete();
writer.close();
}
} catch (IOException ioe) {
// log.warn(String.format("Failed to create txt for file: %s", pdf.getName()), ioe);
}
}
示例5: log
import java.io.FileWriter; //导入方法依赖的package包/类
@Override
public void log(String datos) {
File file = new File("log.txt");
try {
FileWriter fW = new FileWriter(file, true);
fW.write(new Date() + " - " + datos + "\n");
fW.close();
} catch (IOException e) {
e.printStackTrace();
}
}
示例6: writeFileLines
import java.io.FileWriter; //导入方法依赖的package包/类
static void writeFileLines(Vector v, File f) throws IOException {
FileWriter write = new FileWriter(f);
for (int i = 0; i < v.size(); i++) {
write.write((String) v.elementAt(i));
write.write(ls);
}
write.flush();
write.close();
}
示例7: write
import java.io.FileWriter; //导入方法依赖的package包/类
public static void write(String path, String data) {
if (!TextUtils.isEmpty(path)) {
try {
FileWriter writer = new FileWriter(path);
writer.write(data);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
示例8: saveToFile
import java.io.FileWriter; //导入方法依赖的package包/类
public void saveToFile(Object data, File location){
XStream xstream = new XStream(new DomDriver());
String content = xstream.toXML(data);
try {
FileWriter fileWriter = new FileWriter(location);
fileWriter.write(content);
fileWriter.close();
} catch (Exception e) {
// user clicked cancel. No need to exclaim anything went wrong
}
}
示例9: appendDataToTempFile
import java.io.FileWriter; //导入方法依赖的package包/类
/**
* Appends the given data to the file specified in the input and returns the
* reference to the file.
*
* @param file
* @param dataToAppend
* @return reference to the file.
* @throws IOException
*/
public static File appendDataToTempFile(File file, String dataToAppend)
throws IOException {
FileWriter outputWriter = new FileWriter(file);
try {
outputWriter.append(dataToAppend);
} finally {
outputWriter.close();
}
return file;
}
示例10: main
import java.io.FileWriter; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
public static void main(String[] args) throws Exception {
Class[] voClassesInPackage = getClasses(VO_VERSION_PACKAGE);
VOConverterTestGenerator generator = new VOConverterTestGenerator(
voClassesInPackage);
FileWriter fw = null;
try {
fw = generator.createOutputFile();
generator.writeCode(fw);
} finally {
if (fw != null) {
fw.close();
}
}
}
示例11: writerToFile
import java.io.FileWriter; //导入方法依赖的package包/类
private static void writerToFile(File file, String contents) throws Throwable {
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
FileWriter filewriter = new FileWriter(file);
filewriter.write(contents);
filewriter.flush();
filewriter.close();
}
示例12: writeFile
import java.io.FileWriter; //导入方法依赖的package包/类
private static void writeFile(String output, File file, boolean append) {
try {
FileWriter writer = new FileWriter(file, append);
writer.write(output);
writer.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例13: export
import java.io.FileWriter; //导入方法依赖的package包/类
/**
* The export method is used to carry out the writing to the CSV File. This
* method calls other helper methods which perform the writing operations.
*
* @param csvFilePath path to which the file will be exported.
* @throws IOException
*/
public void export(final String csvFilePath) throws IOException {
final FileWriter writer = new FileWriter(csvFilePath);
try {
// Total Number of Components
writeHeader(writer, "Component Summary");
totalCounts(writer);
CSVUtils.writeLine(writer, Arrays.asList("")); // empty line
// Total Number of sub-types of the Components such as Comm Points, Routes, Filters and Definitions.
writeHeader(writer, "Total Number of types of Components");
totalCommPointTypes(writer);
// general properties of each comm point:
generalProperties(writer);
totalFilterTypes(writer);
totalFilterCountsPerRoute(writer);
totalDefinitionsCountsPerRoute(writer);
totalDefinitionTypes(writer);
// Add the Rhapsody Version numbers
rhapsodyVersionNumbers(writer);
writer.flush();
} finally {
writer.close();
}
}
示例14: writeFile
import java.io.FileWriter; //导入方法依赖的package包/类
static File writeFile(File base, String path, String body) throws IOException {
File f = new File(base, path);
FileWriter out = new FileWriter(f);
out.write(body);
out.close();
System.err.println("wrote " + path + ": " + body);
return f;
}
示例15: saveSchema
import java.io.FileWriter; //导入方法依赖的package包/类
@BeforeClass
public static void saveSchema() throws IOException {
oldTestBuildDataProp = System.getProperty(TEST_BUILD_DATA_KEY);
System.setProperty(TEST_BUILD_DATA_KEY, DFS_DIR);
FileWriter schema = new FileWriter(SCHEMA_FILE);
schema.append(RECORD_SCHEMA.toString());
schema.close();
}