473,800 Members | 2,323 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to get the package name from a String variable consisting of the java file name??

18 New Member
Hi All..
i need a small help...i will present the scenario in the best possible manner please help...

We are asking the user to browse a file...
and using that file path we are getting the java file name, into an String variable.
Now we need to know the package name of that java file for proceeding further...
So can anyone suggest a way to do the same...

Thanks....
Jul 23 '07 #1
3 2998
JosAH
11,448 Recognized Expert MVP
Hi All..
i need a small help...i will present the scenario in the best possible manner please help...

We are asking the user to browse a file...
and using that file path we are getting the java file name, into an String variable.
Now we need to know the package name of that java file for proceeding further...
So can anyone suggest a way to do the same...

Thanks....
You have to open that file for reading; search for the first occurrence of the
words 'pacakge'; skipt the followin spaces and everything up to a semi colon
is the package name. Regular expressions can come in handy here.

kind regards,

Jos
Jul 23 '07 #2
r035198x
13,262 MVP
Hi All..
i need a small help...i will present the scenario in the best possible manner please help...

We are asking the user to browse a file...
and using that file path we are getting the java file name, into an String variable.
Now we need to know the package name of that java file for proceeding further...
So can anyone suggest a way to do the same...

Thanks....
I'd say java classes (not Java files) are the ones that are grouped into packages. The package name is part of the fully qualified name returned by the Class.getName method so if you have the class you can do something like

Expand|Select|Wrap|Line Numbers
  1.  public static String getPackageName(Class class) {
  2.        String fullName = class.getName();
  3.        int lastDot = fullName.lastIndexOf ('.');
  4.        if (lastDot == -1) {
  5.            return "default"; //the class is in the default package
  6.        }
  7.        return fullName.substring (0, lastDot);
  8.    }
Jul 23 '07 #3
Sushmita
18 New Member
You have to open that file for reading; search for the first occurrence of the
words 'pacakge'; skipt the followin spaces and everything up to a semi colon
is the package name. Regular expressions can come in handy here.

kind regards,

Jos



it worked.. :)
Thanku...
Jul 23 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

23
2167
by: Yannick Patois | last post by:
Hi, Under some naming conditions of module files, it seems that python lost class static variables values. It seems only to append when importing a "badly" named module that itself import a module with a static variable in it (looks complex, but see the example below, pretty simple): First a working example: <<<< file: aTest.py
2
7282
by: Theodore Feldman | last post by:
If connection properties and global variables are set from an INI file, how can a DTS package be made truly portable? If the INI file pathname is hard-coded in the package, it must be edited when you copy the package to a new environment; otherwise your packages in multiple environments will all reference the same INI file. If there are dozens of properties that need to be set dynamically (for example, connections that reference...
10
2626
by: vivekian | last post by:
Hi , New to dot net and C# and was wondering what is the equivalent of a java package in dot net ? thanks, vivekian
1
1694
by: ewehbe | last post by:
I am trying to call this command from an access data base through RUNAPP macro commande: "C:\program files\microsoft sql server\80\Tools\Binn\dtsrun.exe" /S "(local)" /N "mypackage" /E /A mydate:8 = "Forms!Opensituation!Combo4" mypackage: is the name of the dts package in sqlserver mydate is the name of the global variable used in sql server 8 is the string type Forms!Opensituation!Combo4: is the combo box variable in the access form...
14
2135
by: Richard Harter | last post by:
Apologies for the length - this post is best viewed with fixed font and a line width >= 72. Below is the source code for a C header file that provides a suite of storage management macros. I am asking for comments on it. In particular: Are there any gotchas that I have overlooked? Are there any suggestions for improvements? Is there a generally available superior packages to do the same thing with the same general licensing? ...
5
3135
by: selimsivad83 | last post by:
Hi everyone, Thinking in Java, 4th edition, p 232: ... if you don't put an access specifier for class access, it defaults to package access. ... However, if a static member of that class is public, the client programmer can still access that static member even though they cannot create an object of that class. However the code below produces an error:...
33
15586
by: Michael B Allen | last post by:
Hello, Early on I decided that all text (what most people call "strings" ) in my code would be unsigned char *. The reasoning is that the elements of these arrays are decidedly not signed. In fact, they may not even represent complete characters. At this point I think of text as simple binary blobs. What charset, character encoding and termination they use should not be exposed in the interface used to operate on them. But now I have...
1
1475
by: =?Utf-8?B?S3VtYXIuQS5QLlA=?= | last post by:
My requirement is as follows: Dot net code calls a DTS package. DTS package has a dynamic variable saying the input file given is xyz.xls in some path on the drive, and it is mentioned to take data from Sheet1 of the xls However during code execution, the xls is renamed as say, abc.xls. I am also changing the value of the variable with the new name of the file However, the DTS fails execution saying it cannot find the rows to transform....
2
1313
by: yulam4u | last post by:
hello people!!! i am having this problem while i am implementing inheritance in a package named"inherint" which is a sub-directory of the directory "shashikayubbi"!!! i've a super class inhr.java,a derived class inher.java !!! well the code runs completely ok when i am executing it from the directory "shashikayubbi" , but when i put these files in the sub-dir "inherint" there is a problem at the time of compliling the code and the...
0
10505
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10276
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10035
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9090
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6813
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.