[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 208
  • Last Modified:

Logon user name using API for window95

SDK : JDK1.1.1.5
Development Platform : windows95

I don't know how can I use API in JAVA which I was using in VB5.
I just want to get logon user login name and IP address?
0
raza
Asked:
raza
  • 5
  • 4
1 Solution
 
msmolyakCommented:
Java is cross-platform that is why it does not provide any system-specific infromation like user name. As for the IP address it is:

InetAddress.getLocalHost().getHostAddress()

If you need to talk to Windows API you can probably do it using native calls.

Let me know if you need more info.
0
 
razaAuthor Commented:
thanks
if it is  posible then please send me info about how to read windows text file from windows dirctory ?
0
 
msmolyakCommented:
I might be wrong on the first account. To get the user's name try

Properties props = System.getProperties();
String username = props.getProperty("user.name");

This assumes that you are running a Java application which is allowed to read the system properties. Applets can read only some properties, the user.name is probably not one of them

Let me know if you still need the info on reading the text files.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
razaAuthor Commented:
thanks
if it is  posible then please send me info about how to read windows text file from windows dirctory ?
0
 
msmolyakCommented:
BufferedReader reader = new BufferedReader(FileReader(filename));

String line;
while((line = reader.readLine()) != null)
{
  // Process the line
}

0
 
razaAuthor Commented:
would u please help me to debug it out
I m getting below 3 erorrs

Compiling D:\jdk1.1.5\Program\Logonuser\Logonuser.java
D:\jdk1.1.5\Program\Logonuser\Logonuser.java:16: Variable 'UserName' is already defined in this method.
            String UserName = props.getProperty("user.name");
                   ^
D:\jdk1.1.5\Program\Logonuser\Logonuser.java:22: Invalid type expression.
            System.out.println(UserName)
                              ^
D:\jdk1.1.5\Program\Logonuser\Logonuser.java:23: Invalid declaration.
            g.drawString("Hello Logonuser!", j50, 50);
                        ^
3 errors
Finished

/* here is source
=========*/
import java.awt.*;
import java.util.Properties;
public class Logonuser extends java.applet.Applet
{
      public void init()
      {
            String UserName;
            Properties props = System.getProperties();
            String UserName = props.getProperty("user.name");
            resize(300,300);
      }

      public void paint(Graphics g)
      {
            System.out.println(UserName)

      }
}



0
 
razaAuthor Commented:
I m sorry above is wrong posting the currect one is below



Compiling D:\jdk1.1.5\Program\Logonuser\Logonuser.java
D:\jdk1.1.5\Program\Logonuser\Logonuser.java:11: Variable 'UserName' is already defined in this method.
            String UserName = props.getProperty("user.name");
                   ^
D:\jdk1.1.5\Program\Logonuser\Logonuser.java:17: Undefined variable: UserName
            System.out.println(UserName);
                               ^
2 errors
Finished






import java.awt.*;
import java.util.Properties;

public class Logonuser extends java.applet.Applet
{
      public void init()
      {
            String UserName;
            Properties props = System.getProperties();
            String UserName = props.getProperty("user.name");
            resize(300,300);
      }

      public void paint(Graphics g)
      {
            System.out.println(UserName);
      }
}



0
 
msmolyakCommented:
      import java.awt.*;
       import java.util.Properties;
       public class Logonuser extends java.applet.Applet
       {
       String UserName;
       public void init()
       {
       Properties props = System.getProperties();
       UserName = props.getProperty("user.name");
       resize(300,300);
       }

       public void paint(Graphics g)
       {
       System.out.println(UserName)

       }
       }

I doubt though an applet can read the user name.
0
 
razaAuthor Commented:
I m sorry above is wrong posting the currect one is below



Compiling D:\jdk1.1.5\Program\Logonuser\Logonuser.java
D:\jdk1.1.5\Program\Logonuser\Logonuser.java:11: Variable 'UserName' is already defined in this method.
            String UserName = props.getProperty("user.name");
                   ^
D:\jdk1.1.5\Program\Logonuser\Logonuser.java:17: Undefined variable: UserName
            System.out.println(UserName);
                               ^
2 errors
Finished






import java.awt.*;
import java.util.Properties;

public class Logonuser extends java.applet.Applet
{
      public void init()
      {
            String UserName;
            Properties props = System.getProperties();
            String UserName = props.getProperty("user.name");
            resize(300,300);
      }

      public void paint(Graphics g)
      {
            System.out.println(UserName);
      }
}



0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now