- 论坛徽章:
- 0
|
读取系统信息的API函数在哪儿?
读取INI文件的函数自己写的,贴出来评一下.看一下有什么问题啊?
参数列表:
参数1:项目名
参数2:子项目名
参数3:INI文件名.
以下为代码:
- import java.lang.*;
- import java.io.*;
- class test{
- /**@READ INI FILE
- @WRITE BY YL
- @PRAM 1:
- @PRAM 2:
- @PRAM 3:
- @
- @ */
- static String Readfile(String str1,String str2,String str3){
- try {
- File inFile = new File( str3 );
- FileInputStream inStream = new FileInputStream(inFile);
- String strTemp= new String();
- int i = 0;
- int j = 0;
- int x = 0;
- boolean blnFlg = false;
-
- byte[] data = new byte[(int)inFile.length()];
- if (inStream.read(data) <= 0){
- System.err.println("Exception: Ini file is empty.");
- }
- for (i=0;i<(int)inFile.length();i++){
- //System.out.print("Length:");
- //System.out.println(i);
- if (data[i]==(byte)'\''){
- for (j=i;data[j]!=(byte)'\n';j++);
- strTemp = new String(data, i+1,j-i-1);
- i=j;
- //System.out.print("COMMENT:");
- //System.out.println(strTemp);
- }
- if(blnFlg){
- //get value
- //System.out.println("true");
- for (j=i+1;data[j]!=(byte)'\n';j++);{ //readline
- strTemp = new String(data, i+1,j-i-1);
- }
- x = strTemp.indexOf('=');
- if (x <=0) continue;
- //System.out.println(strTemp.substring(0,x));
- if (strTemp.substring(0,x).equals(str2))
- return strTemp.substring(x+1,strTemp.length()-1);
- }
- if (data[i]==(byte)'['){//seach object :
- for (j=i;data[j]!=(byte)']';j++);
- strTemp = new String(data, i+1,j-i-1);
- i=j;
- //System.out.print("VALUE----");
- //System.out.println(strTemp);
- blnFlg=strTemp.equals(str1);
- }
- }
- }
- catch (FileNotFoundException e){
- System.err.println("Errmsg09");
- System.err.println("Exception: couldn't find the Ini file.");
- }
- catch (IOException e){
- System.err.println("Exception: couldn't read the Ini file.");
- }
- System.out.println("strTemp");
- return str3;
- }
- public static void main(String[] args) {
- try {
- String aa = new String("DATABASE");
- String bb = new String("DRIVER");
- String F = new String ("e:\\java\\cell.ini");
- System.out.println("Length is : "+Readfile(aa,bb,F).length());
- System.out.println("Values is : "+Readfile(aa,bb,F));
- }
- catch(Exception e) {
- e.printStackTrace();
- }
- }
- }
复制代码
见笑了! |
|