當前位置: 首頁>>代碼示例>>Java>>正文


Java FileWriter類代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:26,代碼來源:ZooInspectorManagerImpl.java

示例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");
		}
	}
 
開發者ID:Maximuspayne,項目名稱:NavyCraft2-Lite,代碼行數:19,代碼來源:CraftMover.java

示例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();
    }
}
 
開發者ID:Su-Yong,項目名稱:NewKakaoBot,代碼行數:29,代碼來源:FileManager.java

示例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();
		}
	}
}
 
開發者ID:andykuo1,項目名稱:candlelight,代碼行數:23,代碼來源:Ludwig.java

示例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]);
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:25,代碼來源:TestConfiguration.java

示例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;
        }
    }
}
 
開發者ID:souhaib100,項目名稱:MARF-for-Android,代碼行數:31,代碼來源:SyntaxError.java

示例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();
}
 
開發者ID:dataloom,項目名稱:integrations,代碼行數:24,代碼來源:ConvertImages.java

示例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();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:21,代碼來源:TopLoggingOwnConfigTest.java

示例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;
}
 
開發者ID:knowrafa,項目名稱:lembredio,代碼行數:22,代碼來源:Farmaceutico.java

示例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();
}
 
開發者ID:zhangyingwei,項目名稱:cockroach,代碼行數:24,代碼來源:NameStore.java

示例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) {}
 }
 
開發者ID:ate47,項目名稱:ATEBot,代碼行數:18,代碼來源:Main.java

示例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();
	}
}
 
開發者ID:Detea,項目名稱:PekaED,代碼行數:21,代碼來源:EpisodePanel.java

示例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");
	}
}
 
開發者ID:stlgolfer,項目名稱:Soup,代碼行數:29,代碼來源:HTMLGen.java

示例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();
    }

}
 
開發者ID:RJMillerLab,項目名稱:ibench,代碼行數:24,代碼來源:HTMLPresenter.java

示例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);
        }
    }
}
 
開發者ID:easymall,項目名稱:easy-test,代碼行數:18,代碼來源:FindNotMakeTest.java


注:本文中的java.io.FileWriter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。