📄 fileaction.java
字号:
/*
* fileAction.java
*
* Created on 2006年12月13日, 上午9:57
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package checkspelling;
import java.io.*;
import java.util.zip.*;
public class fileAction {
private String DicPath;
private String FilePath;
private String SaveObjectName;
private String Result;
private String LastLine;
private int Line;
private File ZipSource;
private File ZipObject;
private int MAXWORDS=50;
private int Position=0;
private char temp=' ';
StringBuffer error=new StringBuffer();
public fileAction() {
}
/*
*get the values from otherwhere
*/
public void setDicPath(String dicPath){
this.DicPath=dicPath;
}
public String getDicPath(){
return DicPath;
}
public void setFilePath(String filePath){
this.FilePath=filePath;
}
public String getFilePath(){
return FilePath;
}
public void setZipSource(File ZipSource){
this.ZipSource=ZipSource;
}
public File getZipSource(){
return ZipSource;
}
public void setZipObject(File ZipObject){
this.ZipObject=ZipObject;
}
public File getZipObject(){
return ZipObject;
}
public void setSaveObjectName(String SaveObjectName){
this.SaveObjectName=SaveObjectName;
}
public String getSaveObjectName(){
return SaveObjectName;
}
public void setResult(String Result){
this.Result=Result;
}
public String getResult(){
return Result;
}
public String getLastLine(){
return LastLine;
}
public int getLine(){
return Line;
}
/**
*a method used to check the spelling file
*/
public void checkFile() throws IOException{
FileReader in=new FileReader(getFilePath());
StringBuffer input=new StringBuffer();
int c;
String TempWord="";
Line=1;
LastLine="";
while((c=in.read())!=-1){
temp=(char)c;
if(temp=='\n'){
Line++;
// Position=0;
}
if((temp>='a'&&temp<='z')||(temp>='A'&&temp<='Z')){
input.append(temp);
LastLine=input.toString();
}
else{
TempWord=input.toString().trim();
if(!TempWord.equals("")){
error.append(searchDic(TempWord,Line));
}
input=new StringBuffer();
}
}
in.close();
}
public String searchDic(String input,int Line) throws IOException{
FileReader reader=new FileReader(getDicPath());
BufferedReader in=new BufferedReader(reader);
StringBuffer stringBuffer=new StringBuffer();
String dic,error="";
// Position++;
boolean isExist=false;
while((dic=in.readLine())!=null){
if(input.equals(dic)){
isExist=true;
break;
}
}
if(!isExist){
error="位于第"+Line+"行,出错单词为"+input+"\n";
}
reader.close();
in.close();
return error;
}
/*
*/
public StringBuffer LastLine() throws IOException{
if((temp>='a'&&temp<='z')||(temp>='A'&&temp<='Z')){
error.append(searchDic(getLastLine(),getLine()));
}
if(error.length()<2){
error.append("拼写文件没有错误!");
}
return error;
}
/*
*define a method used to zip files
*/
public boolean zipFile(){
if(getZipObject()!=null&&getZipSource()!=null){
try{
FileInputStream fileInput=new FileInputStream(getZipSource());
DataInputStream in=new DataInputStream(fileInput);
//create an input stream
FileOutputStream fileOutput=new FileOutputStream(getZipObject());
DataOutputStream dataOut=new DataOutputStream(fileOutput);
ZipOutputStream out=new ZipOutputStream(dataOut);
//create a zip stream
out.putNextEntry(new ZipEntry(getZipSource().getPath()));
int i;
while((i=in.read())!=-1){
out.write(i);
}
in.close();
out.close();
return true;
}
catch(Exception e){
return false;
}
}
else{
return false;
}
}
/*
*define a method used to save files
*/
public boolean save(){
if(getSaveObjectName()==null){
return false;
}
try{
File file=new File(getSaveObjectName());
FileWriter out=new FileWriter(file);
out.write(getResult());
out.close();
return true;
}catch(Exception e){}
return false;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -