473,414 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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

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 2979
JosAH
11,448 Expert 8TB
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 8TB
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
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
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...
2
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...
10
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
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...
14
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...
5
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...
33
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...
1
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...
2
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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,...
0
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...

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.