📄 gstextfile.java
字号:
package jp.co.sjts.gsession.tools;
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;
/**
* <p>嫟捠僥僉僗僩僼傽僀儖梡婎杮僋儔僗
*
* @author Satoru K <koni@sjts.co.jp>
*/
abstract public class GSTextFile{
/** 暥帤僐乕僪 */
private String enc = "EUCJIS";
/** 僼傽僀儖僆僽僕僃僋僩傪庢摼偟傑偡丅 */
abstract protected File GetFile();
/** 僼傽僀儖撉傒崬傒 */
abstract protected void Read(BufferedReader bf) throws GSException;
/** 僼傽僀儖弌椡 */
abstract protected void Write(PrintWriter pw) throws GSException;
/**
* 儘僢僋
*/
private File GetLockFile(){
String buf = GetFile().getPath()+".Lock";
return new File(buf);
}
/**
*
*/
public void setEncode(String enc){
this.enc = enc;
}
/**
*
*/
public void Lock() throws GSException{
while(GetLockFile().exists()){
try {
Thread.sleep(100);
}catch(InterruptedException e){
}
}
GetLockFile().mkdir();
}
/**
*
*/
public void Unlock() throws GSException{
GetLockFile().delete();
}
/**
*
*/
public final synchronized void Load() throws GSException{
try {
InputStreamReader isr = new InputStreamReader(new FileInputStream(GetFile()),enc);
BufferedReader bf = new BufferedReader(isr);
Read(bf);
bf.close();
} catch(GSException e) {
throw new GSException("僼傽僀儖撉崬傒僄儔乕",e);
} catch(FileNotFoundException e) {
throw new GSException("僼傽僀儖偑尒偮偐傝傑偣傫",e);
} catch(IOException e){
throw new GSException("IO僄儔乕",e);
}
}
/**
*
*/
public final synchronized void Save() throws GSException{
try {
OutputStreamWriter osw = new OutputStreamWriter( new FileOutputStream(GetFile()),enc);
PrintWriter pw = new PrintWriter(osw);
Write(pw);
pw.flush();
pw.close();
} catch(GSException e) {
throw new GSException(e.toString(),e);
} catch(IOException e) {
throw new GSException("IO僄儔乕",e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -