• C

convert struct to Java

how do I convert this to Java?
struct stat statb;
LVL 17
Tacobell777Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

fridomCEO/ProgrammerCommented:
Well what do you want do do. Define a new class find the Java counterpart or what else?

I assume you look for the java counter part for getting informations about files.
You want to visi java.io.File. You can use it like this:

import java.io.*;


public class JavaFileTest {
            
      public static void main(String[] args) {
            String  file_name = "/home/frido/.zshrc";
            File some_file;
            some_file = new File(file_name);
            System.out.println("lenght of " + file_name + " is " + some_file.length());
            
      }
}

output:
lenght of /home/frido/.zshrc is 3499

If tha is not what you're looking for you have to tell us what you really want.

Regards
Friedrich
arun_vipCommented:
Hi,
In Java, we don't have any concept called structure. Since, Java is pure object oriented programming everything is object. So in C if you struct then you need to convert to class in Java.
Example
struct st
{
 int a;
 float b;
};

class A
{
 public int a;
 public float b;
}
furqanchandioCommented:
hi

in c/c++ the only difference between a struct and class is that in struct everything by default is public and in a class everthing is in private by default.

you can even inherit a class from a structure and vice versa, i have done it in turbo c ( but same cant be done with unions)

plus in c/c++ the main function lies outside the class/structure  as a global function.
furqanchandioCommented:
>> struct stat statb;

first i suggest is to replace struct with class and place a main() function in stat if required

cheers
MysidiaCommented:
Let me guess, you have
an #include <sys/stat.h>

In your C code?

There is no direct translation to Java.

import java.io.File;
...

File xyz = new File("blah.txt");

Then lookup  
 http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html

To figure out what methods you need to call to get the information
you want about a file.

Unfortunately, there will be no direct java equivalent to the stat() function
provided by the POSIX API under Unix.

You would need to develop the code that depends on it in another language
like C or C++

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.