易截截图软件、单文件、免安装、纯绿色、仅160KB

java 用文件对话框打开文件

//文件的打开
import java.awt.FileDialog;
import java.awt.event.*;
import java.io.*;
import java.io.File;
import java.io.FileReader;
public class FileOpen {
private FileDialog filedialog_open;
private String fileopen = null, filename = null;// 用于存放打开文件地址 和文件名
private File file1; // 文件字节流对象
private FileReader file_reader;//文件字符流对象
private BufferedReader in;//文件行读取 写入对象
private StringBuffer text = new StringBuffer();

HaffmanFrame haffman= null;
FileOpen(HaffmanFrame hf) {
haffman = hf;
filedialog_open = new FileDialog(haffman, "打开文件对话框", FileDialog.LOAD);
// 打开文件对话框适配器
filedialog_open.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
filedialog_open.setVisible(false);
}
});
}
public void open() {
String s = "";
filedialog_open.setVisible(true);
fileopen = filedialog_open.getDirectory();// 返回文件对话框中显示的文件所属的目录
filename = filedialog_open.getFile();// 返回当前文件对话框中显示的文件名的字符串表示
// 如果不存在就返回NULL
if (filename != null)// 判断打开的文件是否存在
{
try {
file1 = new File(fileopen,filename );
file_reader = new FileReader(file1);
in = new BufferedReader(file_reader);//每次读取一行
while ((s = in.readLine()) != null)
text.append(s + '\n');
in.close();
file_reader.close();
} catch (IOException e2) {
System.out.println("不能打开文件!");
}
}
}
//返回得到的文本字符串
public String getText() {
return new String(text);
}
}


相关文档:

JAVA基础知识

AVA相关基础知识 
1、面向对象的特征有哪些方面 
1.抽象: 
抽象就是忽略一个主题中与当前目标无关的那些方面,以便更充分地注意与当前目标有关的方面。抽象并不打算了解全部问题,而只是选择其中的一部分,暂时不用部分细节。抽象包括两个方面,一是过程抽象,二是数据抽象。 
2.继承: 
继 ......

Java 遍历 Map

Map m = new HashMap();
for (Object o : map.keySet()){
map.get(o);
}

JDK1.4

Map map = new HashMap() ;

Iterator it = map.entrySet().iterator() ;
while (it.hasNext())
{
Map.Entry entry = (Map ......

用Java读取pdf中的数据

用Java简单的读取pdf文件中的数据:第一步:下载PDFBox-0.7.2.jar。提供一个下载地址:http://pdfhome.hope.com.cn/Resource.aspx?CID=63844604-5253-4ae1- b023-258c9e324061&RID=20cd8f94-1cee-40b6-a3df-0ef024f8e0d2解压后,把lib文件下的PDFBox-0.7.2.jar,PDFBox-0.7.2-log4j.jar放到你classpath路径下。(我把源 ......

JAVA获取系统当前时间

//导入
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;     Date dt=new Date();//如果不需要格式,可直接用dt,dt就是当前系统时间
DateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");//设置显示格式
String nowTime=" ......

java 字符串分割

●利用split函数: String s = new String("2_8_7_4_3_9_1"); String[] arr = s.split("_"); Java中用split函数进行分割字符串。 1.语法如下 String.split(sourceStr,maxSplit) String.split(sourceStr) 参数说明:sourceStr是被分割的字符串,maxSplit是最大的分割数 返回值说明:split函数的返回值是一个字 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号