Re: read file in my own .jar
"Jim C." <[email protected]> Fri, 28 Jul 2006 08:31:15 -0700
| Newsgroups | gmane.comp.java.linux.general |
|---|---|
| Message-ID | <[email protected]> |
phlinux wrote:
> Hello,
>
> java -jar myapplication.jar
>
> will launch my java application. I want that this application reads some
> file from a .jar file.
>
> On the internet I found a lot of samples for this job, but of course I
> need the name of the .jar file.
>
> The name of .jar file is myapplication.jar. But how to get it ?
>
> In Linux, with C program argv[0] is name of the program.
>
> My question is : How can I find that the running program is
> myapplication.jar ? Is there a portable mechanism
> in java taht is linke the argv[0] in C context ?
Look closely at the declaration of your main method. There should be
parameters there. If not, it can be re-written. Here is an example which
you can see the parameters but they are not used. The idea behind this
was to double check and see if 25gigabytes would fit in a Long value:
public class LongValueChecker
{
Long _longValue;
public static void main ( String[] args )
{
LongValueChecker app = new LongValueChecker();
app._longValue = new Long(( new Long(27) * new Long(1073741824) ));
System.out.println ( app._longValue );
System.out.println ( Long.MAX_VALUE );
}
}
The output is:
28991029248
9223372036854775807
So in other words a Long value can hold 25 Gigabytes on the order of
tens of millions of times over.
String[] args at the main declaration is where you get arguments from.
Wirte your self an experimental program that accepts a parameter and
then prints it using System.out.println().
Jim C.
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]