本文整理汇总了Java中java.io.FileWriter类的典型用法代码示例。如果您正苦于以下问题:Java FileWriter类的具体用法?Java FileWriter怎么用?Java FileWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileWriter类属于java.io包,在下文中一共展示了FileWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveNodeViewersFile
import java.io.FileWriter; //导入依赖的package包/类
public void saveNodeViewersFile(File selectedFile,
List<String> nodeViewersClassNames) throws IOException {
if (!selectedFile.exists()) {
if (!selectedFile.createNewFile()) {
throw new IOException(
"Failed to create node viewers configuration file: "
+ selectedFile.getAbsolutePath());
}
}
FileWriter writer = new FileWriter(selectedFile);
try {
BufferedWriter buff = new BufferedWriter(writer);
try {
for (String nodeViewersClassName : nodeViewersClassNames) {
buff.append(nodeViewersClassName);
buff.append("\n");
}
} finally {
buff.flush();
buff.close();
}
} finally {
writer.close();
}
}
示例2: battleLogger
import java.io.FileWriter; //导入依赖的package包/类
public static void battleLogger(String str) {
String path = File.separator + "BattleLog.txt";
File file = new File(path);
try {
FileWriter fw = new FileWriter(file.getName(), true);
BufferedWriter bw = new BufferedWriter(fw);
Date now = new Date();
bw.write(DateFormat.getDateInstance(DateFormat.SHORT).format(now) + " " + DateFormat.getTimeInstance().format(now) + " - " + str);
bw.newLine();
bw.flush();
bw.close();
} catch (Exception e) {
System.out.println("Battle log failure");
}
}
示例3: removeData
import java.io.FileWriter; //导入依赖的package包/类
public void removeData(String path, String key) {
createFile(path);
try {
BufferedReader reader = new BufferedReader(new FileReader(new File(KAKAOBOT_HOME, path)));
String line;
StringBuilder result = new StringBuilder();
while((line = reader.readLine()) != null) {
result.append(line);
result.append("\n");
}
JSONObject json = new JSONObject(result.toString() + "");
json.remove(key);
BufferedWriter writer = new BufferedWriter(new FileWriter(new File(KAKAOBOT_HOME, path)));
writer.write(json.toString());
reader.close();
writer.close();
} catch(IOException err) {
err.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}
示例4: saveDungeon
import java.io.FileWriter; //导入依赖的package包/类
private void saveDungeon(Stage stage)
{
FileChooser chooser = new FileChooser();
chooser.setInitialFileName("dungeon.json");
File file = chooser.showSaveDialog(stage);
if (file != null)
{
try
{
BufferedWriter writer = new BufferedWriter(new FileWriter(file));
JSONObject data = Dungeon.writeToJSON(this.dungeon);
JSON.write(writer, data);
writer.flush();
writer.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
示例5: testCompactFormat
import java.io.FileWriter; //导入依赖的package包/类
public void testCompactFormat() throws IOException {
out=new BufferedWriter(new FileWriter(CONFIG));
startConfig();
appendCompactFormatProperty("a", "b");
appendCompactFormatProperty("c", "d", true);
appendCompactFormatProperty("e", "f", false, "g");
endConfig();
Path fileResource = new Path(CONFIG);
Configuration conf = new Configuration(false);
conf.addResource(fileResource);
assertEquals("b", conf.get("a"));
assertEquals("d", conf.get("c"));
Set<String> s = conf.getFinalParameters();
assertEquals(1, s.size());
assertTrue(s.contains("c"));
assertEquals("f", conf.get("e"));
String[] sources = conf.getPropertySources("e");
assertEquals(2, sources.length);
assertEquals("g", sources[0]);
assertEquals(fileResource.toString(), sources[1]);
}
示例6: serialize
import java.io.FileWriter; //导入依赖的package包/类
/**
* Serialization routine.
* TODO: migrate to MARF dump/restore mechanism.
*
* @param piOperation 0 for load (not implemented), 1 for save as text
* @param poFileWriter writer to write the error message to
* @return <code>true</code> if the operation was successful
*/
public boolean serialize(int piOperation, FileWriter poFileWriter) {
if (piOperation == 0) {
// TODO load
System.err.println("LexicalError::serialize(LOAD) - unimplemented");
return false;
} else {
try {
poFileWriter.write
(
"Syntax Error (line " + this.iLineNo + "): " + this.iCurrentErrorCode +
" - " + this.strMessage + ", " +
"faulting token: [" + this.oFaultingToken.getLexeme() + "]\n"
);
return true;
} catch (IOException e) {
System.err.println("SyntaxError::serialize() - " + e.getMessage());
e.printStackTrace(System.err);
return false;
}
}
}
示例7: main
import java.io.FileWriter; //导入依赖的package包/类
public static void main( String[] args ) throws IOException {
if ( args.length != 2 ) {
System.err.println( "Expected usage is ./ConvertImages inputDirectory outputCsvFile" );
}
File directory = new File( args[ 0 ] );
File outputFile = new File( args[ 1 ] );
FileWriter writer = new FileWriter( outputFile );
writer.write("XREF,mugshot\n" );
if ( directory.isDirectory() ) {
for ( File file : directory.listFiles() ) {
if ( file.isFile() && isImage( file.getCanonicalPath() ) ) {
writer.write( new StringBuilder( getXref( file.getName() ) ).append( "," )
.append( encoder.encodeToString( Files.readAllBytes( file.toPath() ) ) ).append( "\n" )
.toString() );
}
}
}
writer.flush();
writer.close();
}
示例8: setUp
import java.io.FileWriter; //导入依赖的package包/类
protected void setUp() throws Exception {
clearWorkDir();
System.setProperty("netbeans.user", getWorkDirPath());
log = new File(getWorkDir(), "own.log");
File cfg = new File(getWorkDir(), "cfg");
FileWriter w = new FileWriter(cfg);
w.write("handlers=java.util.logging.FileHandler\n");
w.write(".level=100\n");
w.write("java.util.logging.FileHandler.pattern=" + log.toString().replace('\\', '/') +"\n");
w.close();
System.setProperty("java.util.logging.config.file", cfg.getPath());
// initialize logging
TopLogging.initialize();
}
示例9: verificaFarmacia
import java.io.FileWriter; //导入依赖的package包/类
public boolean verificaFarmacia() throws FileNotFoundException, IOException{
File file = new File("FarmaciasCadastradas.txt");
if(!file.exists()) file.createNewFile();
InputStream is = new FileInputStream("FarmaciasCadastradas" +".txt");
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String linha;
do{
linha = br.readLine();
if(linha== null) break;
if(linha.equals(nomeFarmacia)) return true;
}while(linha != null);
FileWriter outputfile = new FileWriter(file, true);
PrintWriter out = new PrintWriter(outputfile);
System.out.println(nomeFarmacia);
out.println(nomeFarmacia);
out.flush();
out.close();
return false;
}
示例10: store
import java.io.FileWriter; //导入依赖的package包/类
@Override
public void store(TaskResponse response) throws IOException {
PrintWriter writer = new PrintWriter(new FileWriter("D://"+id+".txt",true),true);
Elements els = response.select("strong");
els.stream().map(el -> el.text().trim())
.filter(name -> !name.contains("第"))
.filter(name -> !name.startsWith("热门"))
.filter(name -> !name.startsWith("找动画"))
.filter(name -> !name.startsWith("凹凸"))
.filter(name -> !name.contains("更多"))
.filter(name -> !name.contains("5068"))
.filter(name -> !name.contains("热播动画"))
.filter(name -> !name.contains("点击浏览"))
.filter(name -> !name.contains("上一页"))
.filter(name -> !name.contains("关于我们"))
.filter(name -> name.length() > 0)
.map(name -> name.split("(")[0].trim().replaceAll(" ",""))
.forEach(name -> {
System.out.println(id+":"+name);
writer.println(name);
});
writer.close();
}
示例11: saveConfig
import java.io.FileWriter; //导入依赖的package包/类
public static void saveConfig(){
try{
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.setPrettyPrinting().enableComplexMapKeySerialization().create();
Map<String, Object> hm = new HashMap<String, Object>();
hm.put("token", token);
hm.put("webNumThreads", webNumThreads);
hm.put("playinformation", playinformation);
hm.put("webPort", webPort);
hm.put("accounts", accounts);
hm.put("messages", messages);
Writer writer = new FileWriter("botsetting.json");
gson.toJson(hm, writer);
writer.close();
}catch (Exception e) {}
}
示例12: saveEpisode
import java.io.FileWriter; //导入依赖的package包/类
public void saveEpisode() {
try {
BufferedWriter w = new BufferedWriter(new FileWriter(Data.currentEpisodePath + File.separatorChar + Data.currentEpisodeFile.getName()));
w.write(Data.currentEpisodeName + "\n");
w.write(Data.currentEpisodePath + "\n");
for (File f : Data.episodeFiles) {
w.write(f.getAbsolutePath() + "\n");
}
w.flush();
w.close();
Data.episodeChanged = false;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例13: generateOutputDocumentation
import java.io.FileWriter; //导入依赖的package包/类
/**
* Generates HTML documentation for the Soup session
* @param title title on the window
* @param description the header of the page
* @throws IOException throws if it cannot store
*/
public static void generateOutputDocumentation(String title, String description) throws IOException {
try {
FileWriter f = new FileWriter(System.getProperty("user.dir") + "\\" + "SoupNoodle.html");
f.write("<style>h1 { color: blue;}p { color: red;}div { display: flex; align-items: center; justify-content: center; flex-direction: column;}</style><title>");
f.write(title);
f.write("</title><center><h1>");
f.write(description + " [" + LocalTime.now().getHour() + ":" + LocalTime.now().getMinute() + "]");
f.write("</h1></center><div><p>Local Vars</p><ul>");
writeVars(f);
f.write("</ul><p>Outputs</p><ul>");
writeOutputs(f);
f.write("</ul></div><div><p>Questions Asked</p><ul>");
writeQuestions(f);
f.write("</ul></div>");
f.close();
System.out.println("Output Generated at " + System.getProperty("user.dir") + "\\" + "SoupNoodle.html");
}
catch (IOException ex) {
System.out.println("Error storing output documentation at " + System.getProperty("user.dir") + "\\" + "SoupNoodle.html");
}
}
示例14: printInHtmlFile
import java.io.FileWriter; //导入依赖的package包/类
/**
* Prints the buffer (which should be in HTML) in a file which will serve
* for the browser by putting before and after the HTML headers
*/
public void printInHtmlFile(StringBuffer buf, String pathPrefix, String file)
{
StringBuffer fbuf = new StringBuffer();
printHTMLHeader(fbuf);
fbuf.append(buf);
printHTMLFooter(fbuf);
try
{
BufferedWriter bufWriter = new BufferedWriter(new FileWriter(new File(pathPrefix, file)));
bufWriter.write(fbuf.toString());
bufWriter.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
示例15: logInfo
import java.io.FileWriter; //导入依赖的package包/类
private void logInfo(String msg) {
if (logPath == null) {
logger.info(msg);
} else {
try {
FileUtils.createFile(logPath);
// WTF windows
FileWriter fw = new FileWriter(logPath, true);
fw.write(msg);
fw.write("\n");
fw.flush();
fw.close();
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
}
}