📄 readfile.java
字号:
import java.io.*;
public class ReadFile
{
String filePath="c:/",fileName="";
public void setFilePath(String s)
{
filePath=s;
try
{
byte a[]=filePath.getBytes("ISO-8859-1");
filePath=new String(a);
}catch(Exception e){}
}
public String getFilePath(){return filePath;}
public void setFileName(String s)
{
fileName=s;
try
{
byte a[]=fileName.getBytes("ISO-8859-1");
fileName=new String(a);
}catch(Exception e){}
}
public String getFileName(){return fileName;}
public String[] listFile()
{
File dir=new File(filePath);
String file_name[]=dir.list();
return file_name;
}
public StringBuffer readFile()
{
try
{
File file=new File(filePath,fileName);
FileReader in=new FileReader(file);
PushbackReader push=new PushbackReader(in);
StringBuffer stringbuffer=new StringBuffer();
int c;
char b[]=new char[1];
while((c=push.read(b,0,1))!=-1)
{
String s=new String(b);
if(s.equals("<"))
{
push.unread('&');
push.read(b,0,1);
stringbuffer.append(new String(b));
push.unread('L');
push.read(b,0,1);
stringbuffer.append(new String(b));
push.unread('T');
push.read(b,0,1);
stringbuffer.append(new String(b));
}
else if(s.equals(">"))
{
push.unread('&');
push.read(b,0,1);
stringbuffer.append(new String(b));
push.unread('G');
push.read(b,0,1);
stringbuffer.append(new String(b));
push.unread('T');
push.read(b,0,1);
stringbuffer.append(new String(b));
}
else if(s.equals("\n"))
stringbuffer.append("<BR>");
else
stringbuffer.append(s);
}
push.close();
in.close();
return stringbuffer;
}catch(IOException e)
{return new StringBuffer("不能读取文件");}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -