免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1878 | 回复: 5
打印 上一主题 下一主题

读取系统信息的API函数在哪儿? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-03-12 09:16 |只看该作者 |倒序浏览
要使用JAVA读取注册表,
和.INI文件.


以上第二个问题可以自己写函数完成
,但是读注册表怎么实现?

附带:
操作系统:WIN2000
IDE:JBUIDER7.0

论坛徽章:
0
2 [报告]
发表于 2003-03-12 09:53 |只看该作者

读取系统信息的API函数在哪儿?

使用jni

论坛徽章:
0
3 [报告]
发表于 2003-03-12 10:07 |只看该作者

读取系统信息的API函数在哪儿?

哪个包里面?
再明了一点??
我没找到jni的类,和相关方法.

论坛徽章:
0
4 [报告]
发表于 2003-03-12 18:50 |只看该作者

读取系统信息的API函数在哪儿?

读取INI文件的函数自己写的,贴出来评一下.看一下有什么问题啊?
参数列表:
参数1:项目名
参数2:子项目名
参数3:INI文件名.
以下为代码:

  1. import java.lang.*;
  2. import java.io.*;
  3. class test{
  4. /**@READ INI FILE
  5.      @WRITE BY YL
  6.      @PRAM 1:
  7.      @PRAM 2:
  8.      @PRAM 3:
  9.      @
  10.      @                                                                                                        */
  11. static String Readfile(String str1,String str2,String str3){
  12.         try {
  13.                 File inFile = new File( str3 );
  14.                 FileInputStream inStream = new FileInputStream(inFile);
  15.                 String strTemp= new String();
  16.                 int i = 0;
  17.                 int j = 0;
  18.                 int x = 0;
  19.                 boolean blnFlg = false;
  20.                
  21.                 byte[] data = new byte[(int)inFile.length()];
  22.                 if (inStream.read(data) <= 0){
  23.                         System.err.println("Exception: Ini file is empty.");
  24.                 }
  25.                 for (i=0;i<(int)inFile.length();i++){
  26.                         //System.out.print("Length:");
  27.                         //System.out.println(i);
  28.                         if (data[i]==(byte)'\''){
  29.                                 for (j=i;data[j]!=(byte)'\n';j++);
  30.                                 strTemp = new String(data, i+1,j-i-1);
  31.                                 i=j;
  32.                                 //System.out.print("COMMENT:");
  33.                                 //System.out.println(strTemp);                               
  34.                         }
  35.                         if(blnFlg){
  36.                                 //get  value
  37.                                 //System.out.println("true");
  38.                                 for (j=i+1;data[j]!=(byte)'\n';j++);{ //readline
  39.                                         strTemp = new String(data, i+1,j-i-1);
  40.                                 }
  41.                                 x = strTemp.indexOf('=');
  42.                                 if (x <=0) continue;
  43.                                 //System.out.println(strTemp.substring(0,x));
  44.                                 if (strTemp.substring(0,x).equals(str2))
  45.                                 return strTemp.substring(x+1,strTemp.length()-1);
  46.                         }
  47.                         if (data[i]==(byte)'['){//seach object :
  48.                                 for (j=i;data[j]!=(byte)']';j++);
  49.                                 strTemp = new String(data, i+1,j-i-1);
  50.                                 i=j;
  51.                                 //System.out.print("VALUE----");
  52.                                 //System.out.println(strTemp);
  53.                                 blnFlg=strTemp.equals(str1);
  54.                         }
  55.                 }
  56.         }
  57.         catch (FileNotFoundException e){
  58.                 System.err.println("Errmsg09");
  59.                 System.err.println("Exception: couldn't find the Ini file.");
  60.         }
  61.         catch (IOException e){
  62.                 System.err.println("Exception: couldn't read the Ini file.");
  63.         }
  64.         System.out.println("strTemp");
  65.         return str3;
  66. }
  67. public static void main(String[] args) {
  68.         try {
  69.                 String aa = new String("DATABASE");
  70.                 String bb = new String("DRIVER");
  71.                 String F = new String ("e:\\java\\cell.ini");
  72.                 System.out.println("Length is :  "+Readfile(aa,bb,F).length());
  73.                 System.out.println("Values is :  "+Readfile(aa,bb,F));
  74.         }
  75.         catch(Exception e) {
  76.                 e.printStackTrace();
  77.         }       
  78. }
  79. }
复制代码

见笑了!

论坛徽章:
0
5 [报告]
发表于 2003-03-13 08:59 |只看该作者

读取系统信息的API函数在哪儿?

呵呵,读写 ini 文件好像可以用 java.util.Properties,例子:
http://www.rgagnon.com/javadetails/java-0024.html

java 不作操作系统相关的事情,比如读写注册表,真要这样,就要用 jni 了。

论坛徽章:
0
6 [报告]
发表于 2003-03-14 09:01 |只看该作者

读取系统信息的API函数在哪儿?

谢谢CINC, 问题解决了,!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP