用Java编写:

来源:百度知道 编辑:UC知道 时间:2024/05/17 06:04:13
编写一个Java程序读取Windows目录下的win.ini文件,并打印输出其内容。

我组你一个例子程序吧.
//以下是my.ini的文件内容
company=cie
author=ljb
copyright=2006-2007
//以下是读取这个文件的源代码
import java.io.*;
import java.util.*;

public class PropTest
{
public static void main(String[] args)
{
// TODO 自动生成方法存根
Properties ps = new Properties();
try
{
ps.load(new FileInputStream("my.ini"));
Enumeration en = ps.propertyNames();

while (en.hasMoreElements())
{
String strKey = (String) en.nextElement();
String strValue = ps.getProperty(strKey);

System.out.println(strKey + " : " + strValue);
}
}
catch (Exception e)
{
// TODO: handle exception
e.printStackTrace();
}
}
}

用BufferedReader和FileReader 写就好了!!

使用文本流对象就可以了。JAVA初级教程一般都有事例