gstextfile_convert.java

来自「一个日本流行的,功能较全的开源Web办公管理(Groupware)系统。」· Java 代码 · 共 91 行

JAVA
91
字号

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;

//import java.lang.Exception;
/**
 * <p>嫟捠僥僉僗僩僼傽僀儖梡婎杮僋儔僗  GSTextFile.java
 * <p>Copyright (C) 1999-2000 Japan Total System Co,LTD
 *
 * @author   Satoru K   &lt;koni@sjts.co.jp&gt;
 */
abstract public class GSTextFile_convert
{
	private String enc = "EUCJIS";

	abstract protected File GetFile();
	abstract protected void Read(BufferedReader bf) throws Exception;
	abstract protected void Write(PrintWriter pw) throws Exception;

	private File GetLockFile()
	{
		String buf = GetFile().getPath()+".Lock";
		return new File(buf);
	}

	public void setEncode(String enc)
	{
		this.enc = enc;
	}

	public void Lock() throws Exception
	{
		while(GetLockFile().exists()){
			try	{
				Thread.sleep(100);
			}catch(InterruptedException e){
			}
		}

		GetLockFile().mkdir();
	}

	public void Unlock() throws Exception
	{
		GetLockFile().delete();
	}

	public final synchronized void Load() throws Exception
	{
		try {
			InputStreamReader isr = new InputStreamReader(new FileInputStream(GetFile()),enc);
			BufferedReader bf = new BufferedReader(isr);

			Read(bf);

			bf.close();
	//	} catch(Exception e) {
	//		throw new Exception("僼傽僀儖撉崬傒僄儔乕");
		} catch(FileNotFoundException e) {
			throw new Exception("僼傽僀儖偑尒偮偐傝傑偣傫");
		} catch(IOException e){
			throw new Exception("IO僄儔乕");
		}
	}

	public final synchronized void Save() throws Exception
	{
		try {
			OutputStreamWriter osw =  new OutputStreamWriter( new FileOutputStream(GetFile()),enc);
			PrintWriter pw = new PrintWriter(osw);

			Write(pw);

			pw.flush();
			pw.close();
	//	} catch(Exception e) {
	//		throw new Exception(e.toString());
		} catch(IOException e) {
			throw new Exception("IO僄儔乕");
		}
	}

}

⌨️ 快捷键说明

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