dojofilestorageprovider.java

来自「Hippo CMS是一个以信息为中心的开源内容管理系统。Hippo CMS目标是」· Java 代码 · 共 55 行

JAVA
55
字号
/**
	This is a simple class that can load, save, and remove 
	files from the native file system. It is needed by Safari and Opera
	for the dojo.storage.browser.FileStorageProvider, since both of
	these platforms have no native way to talk to the file system
	for file:// URLs. Safari supports LiveConnect, but only for talking
	to an applet, not for generic scripting by JavaScript, so we must
	have an applet.

	@author Brad Neuberg, bkn3@columbia.edu
*/

import java.io.*;
import java.util.*;

public class DojoFileStorageProvider{
	public String load(String filePath) 
			throws IOException, FileNotFoundException{
		StringBuffer results = new StringBuffer();
		BufferedReader reader = new BufferedReader(
					new FileReader(filePath));	
		String line = null;
		while((line = reader.readLine()) != null){
			results.append(line);
		}

		reader.close();

		return results.toString();
	}

	public void save(String filePath, String content) 
			throws IOException, FileNotFoundException{
		PrintWriter writer = new PrintWriter(
					new BufferedWriter(
						new FileWriter(filePath, false)));
		writer.print(content);

		writer.close();
	}

	public void remove(String filePath)
			throws IOException, FileNotFoundException{
		File f = new File(filePath);

		if(f.exists() == false || f.isDirectory()){
			return;
		}

		if(f.exists() && f.isFile()){
			f.delete();
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?