473,498 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

class file reading itself

oll3i
679 Contributor
How do i make a .class file read itself ? i need to display its code from .class file (not .java file)

when i try ti simply read the file compiler says it can not find the file or that it can not find the given path
thank You
Jan 2 '09 #1
13 2356
oll3i
679 Contributor
okey i had to provide the full path ... but what if i don't want to give the full path because it will be dependent on the path on my system
Jan 3 '09 #2
JosAH
11,448 Recognized Expert MVP
If that class is in your classpath you can use the Class.getResourseAsStream() method.

kind regards,

Jos
Jan 3 '09 #3
oll3i
679 Contributor
hmm how do i get the length of the InputStream?
Jan 3 '09 #4
JosAH
11,448 Recognized Expert MVP
@oll3i
What do you need it for?

kind regards,

Jos
Jan 3 '09 #5
oll3i
679 Contributor
i need to load it into bytes array

and this.getClass().getClassLoader().getResourceAsStre am("nameOfTheFile.class");
throws NullPointerException ?
Jan 3 '09 #6
oll3i
679 Contributor
i added py package name in the path "\\pd15\\nameodtheclass.class"
and now i get
java.io.IOException: Could not completely read file "
Jan 3 '09 #7
JosAH
11,448 Recognized Expert MVP
@oll3i
Can you show us some code? It is quite easy to read everything in a byte array (write the bytes to a ByteArrayOutputStream). Are you trying to read too many bytes?

kind regards,

Jos
Jan 3 '09 #8
oll3i
679 Contributor
there were 1778 bytes when i used ->InputStream is = new FileInputStream(file);

when i use InputStream is = this.getClass().getClassLoader().getResourceAsStre am("\\pd15\\nameOfTheClass.class"); it has less bytes seems like it


Expand|Select|Wrap|Line Numbers
  1. // Ensure all the bytes have been read in
  2.         if (offset < bytes.length) {
  3.             throw new IOException("Could not completely read file ");
  4.         }
  5.  
  6.  
Jan 3 '09 #9
JosAH
11,448 Recognized Expert MVP
@oll3i
You either have to show a bit more of your code or simply use that output stream I mentioned in my previous reply. Those streams don't lie to you.

kind regards,

Jos
Jan 3 '09 #10
oll3i
679 Contributor
thank You Jos i read it :)
Jan 3 '09 #11
JosAH
11,448 Recognized Expert MVP
@oll3i
So does it work now? What was the mistake?

kind regards,

Jos
Jan 3 '09 #12
oll3i
679 Contributor
it works fine and converting bytes works too
the mistake i just left the length of the byte array from the previous code and the array was too big that's all
Jan 3 '09 #13
oll3i
679 Contributor
now i will get to the CAFEBABE part
Jan 3 '09 #14

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

Similar topics

6
2122
by: E G | last post by:
Hi! I am having problems in designing a class. First, I have a base class that allocates a 3D data set and allows some other mathematical operations with it, something like this: template...
7
1137
by: Rob Meade | last post by:
Hi all, Ok - I'm going around in circles and would appreciate some help. I have written a windows service, which up until I tried to be clever was working well :o) I have a main class which...
14
3110
by: Peter Hallett | last post by:
I would like to set up a string array as a class member, or field, and then populate this array by reading in from a text file, but I cannot find the appropriate syntax. The getter and setter are...
12
1335
by: arenium | last post by:
Hi, I'll cut to the chase. I have a class named Foo(). I create an instance of this class named bar, and I set bar.data to a large list of tuples. Within Foo() there is a method which...
3
18519
by: Fernando Chilvarguer | last post by:
Hello! I created a Class Library project in VS2005. Then, using VS, I was able to add a connection string to the project settings, which automaticaly created an app.config file for me. If I try...
6
2154
by: bonk | last post by:
I am trying to create a stream that writes text to a file and: - automatically creates a new file once the current file exceeds a certain size - makes it possible to be used by multiple threads...
20
4001
by: tshad | last post by:
Using VS 2003, I am trying to take a class that I created to create new variable types to handle nulls and track changes to standard variable types. This is for use with database variables. This...
4
2971
by: James Kanze | last post by:
On Aug 13, 5:32 am, Jack Klein <jackkl...@spamcop.netwrote: While you've made a number of important points: In other words, according to the C standard, any signal
6
391
by: Gaijinco | last post by:
I'm trying to do a template class Node. My node.hpp is: #ifndef _NODE_HPP_ #define _NODE_HPP_ namespace com { namespace mnya { namespace carlos { template <typename T>
0
7002
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
7165
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,...
0
7205
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...
0
5462
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,...
1
4910
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...
0
4590
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...
0
1419
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 ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
291
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.