Does main method have to be static? Is there a way to go around it?
I am trying to write a class that will recursively walk through directory listing of a given ftp adress and store it in a text file in this format:
<path> , DIR // if directory
<path> , file // if file
Since I am not yet experienced to do my own socket programming(tried and did not work out) I used Secure iNet Factory's library. And since I will be running multiple instances of this class I concluded that my fields and methods should not be static. Here is the class I wrote:
import com.jscape.inet.ftp.Ftp;
import com.jscape.inet.ftp.FtpException;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import java.util.logging.Level;
import java.util.logging.Logger;
public class test {
private String path = "/";
private String name;
private String adres;
// create new Ftp instance and connect.
public test(String Name, String Adres) throws IOException {
name = Name;
adres = Adres;
System.out.println("Test class: " + name);
try {
Ftp ftp = new Ftp(adres,"anonymous","anonymous");
ftp.connect();
Enumeration e = ftp.getDirListing();
iterate(path, ftp);
ftp.disconnect();
catch (FtpException ex) {
Logger.getLogger(test.class.getName()).log(Level.SEVERE, null, ex);
void iterate(String aStartingDir, Ftp ftp) throws FtpException, IOException {
//Set the path.
path = path + aStartingDir + "/";
// Change directory.
ftp.setDir(aStartingDir);
// Iterate through directory list.
Enumeration e = ftp.getDirListing();
while(e.hasMoreElements()){
Object f = e.nextElement();
// Recursive call if item is directory.
if(f.toString().startsWith("drwxrwxrwx") &&
// Ignore "." and ".."
!f.toString().substring(55).trim().equalsIgnoreCase(".") &&
!f.toString().substring(55).trim().equalsIgnoreCase("..")) {
// Write to index file.
URL dirUrl = FtpCheck.class.getResource("./index/"); // get the directory.
URL fileUrl = new URL(dirUrl, name + ".txt"); // construct the file path.
String filePath = fileUrl.getPath().replaceAll("%20", " "); // fix spaces.
BufferedWriter file = new BufferedWriter(new FileWriter(filePath,true));
file.write((path + f.toString().substring(55).trim()).substring(3)
+ ",DIR\n");
file.close();
iterate(f.toString().substring(55).trim(),ftp);
// Skip entries "." and ".."
else if (f.toString().substring(55).trim().equalsIgnoreCase(".") ||
f.toString().substring(55).trim().equalsIgnoreCase("..")) {
continue;
// Add files to the index.
else {
URL dirUrl = FtpCheck.class.getResource("./index/"); // get the directory.
URL fileUrl = new URL(dirUrl, "index.txt"); // construct the file path.
String filePath = fileUrl.getPath().replaceAll("%20", " "); // fix spaces.
BufferedWriter file = new BufferedWriter(new FileWriter(filePath,true));
file.write((path + f.toString().substring(55).trim()).substring(3)
+ ",file\n");
file.close();
// End of listing reached, go one directory up.
ftp.setDirUp();
// And remove the last directory name from path.
path = path.substring(0,path.lastIndexOf("/"));
path = path.substring(0,path.lastIndexOf("/")) + "/";
}which compiles fine.
Here is the class that invokes it:
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.logging.Level;
import java.util.logging.Logger;
* @author Sentinel
public class NewClass {
public NewClass() {
public static void main(String args[]) throws MalformedURLException, FileNotFoundException, IOException {
index t = new index("El Naga","elnaga.sytes.net");
t.start();
index t1 = new index("Afacan","afacan.myftp.org");
t1.start();
public class index extends Thread {
String name;
String adres;
public index(String Name,String Adres) {
name = Name;
adres = Adres;
@Override
public void run() {
try {
test checker = new test(name,adres);
catch (IOException ex) {
Logger.getLogger(NewClass.class.getName()).log(Level.SEVERE, null, ex);
}when I hit run build fails:
init:
deps-jar:
Compiling 1 source file to C:\Documents and Settings\Sentinel\My Documents\NetBeansProjects\ftpCheck\build\classes
C:\Documents and Settings\Sentinel\My Documents\NetBeansProjects\ftpCheck\src\NewClass.java:19: non-static variable this cannot be referenced from a static context
index t = new index("El Naga","elnaga.sytes.net");
^
C:\Documents and Settings\Sentinel\My Documents\NetBeansProjects\ftpCheck\src\NewClass.java:20: non-static variable this cannot be referenced from a static context
index t1 = new index("Afacan","afacan.myftp.org");
^
2 errors
BUILD FAILED (total time: 0 seconds)I (now)know that main method has to be static. I'm stuck and in need of help to overcome this obstacle. Is there a way to do this?
a stab in the dark, but what if you make index a non-internal class. make it a stand-alone class in it's own file. Either that or make it a static inner class (almost the same thing).
Your problem is that an inner class needs an instance of the outer class to start on, and you're not doing this. Another solution would be to do this kludge:
index t = new NewClass().new index("El Naga","elnaga.sytes.net"); // I think this is how to call itBut again better is to make index a stand-alone class.
Edited by: Encephalopathic on Oct 28, 2008 8:06 AM
Similar Messages
-
When I am trying to import pictures from my iphone to PC, I get the message'No new pictures of videos were found on this device'. There are lots of pictures which i can see on the iphone. I have a 4S. Is there a way to get around that?
It sounds like you are using an application to import. You can do it manually.
Start > Computer (on the right) > scroll to the bottom and you will see your iPhone under Portable Devices > Open it and you will see a Drive, open that and there will be a DCIM folder. That is where your photos will be (There may be other folders each holding photos). -
Is there a way to create a PDF from outlook e-mail that does not embed the attachment? better, is there a way to convert the e-mail with attachement (not embeded) as pdf pages?
- Problem: I have 1400 e-mails with attachments that need to be converted into pdf and the attachments cannot be embeded.
System: PC Windows 7 using Acrobat X Prof. - Thank you!Hi ,
There is an option of embedding index for faster search while converting email to a PDF .
However I am not sure that will serve your purpose or not .
I would recommend you to get in touch with Microsoft support as well .
Meanwhile I'll work on it and get back to you in case I get a desired solution .
Regards
Sukrit Dhingra -
My friend's iPod touch 5th gen is locked somehow for 41 years and she does not have a backup. Is there a way to unlock the iPod without restoring it or loosing the pictures and videos from the camera roll, the applications can be redownloaded and she had no music. Is there any known bug about ipods locking on their own because no one seemed to have tried to bypass the 4 digit code and it is locked for 26 million minutes.So thank you if anyone has any information or help for us.
Your friend may have placed the ipod next to an object that repeatedly pressed the screen. Under certain circumstances this can lead to what appears to the iTouch to be failed attempts to access the system. After repeated failed attempts, the Touch increases the waiting time required for the password and may ultimately lock in the way you describe.
It's been a while since this was posted, but this might be informative to someone else who finds themself in a similar predicament. -
A friend gifted me a copy of The Amazing Spider-man, I redeemed the code, now it tells me I can't download it onto my Ipad (1st Gen) because it does not have a gyroscope. Is there a way for my friend to get his money back, or a way for me to download it?
As a second option I can play on my 1st gen Ipod Touch. Does that have a gyroscope?Contact iTunes Store support staff through the report a problem links in your account history or,
iTunes Customer Service Contact - http://www.apple.com/support/itunes/contact.html > Get iTunes support via Express Lane > iTunes > iTunes Store - Apple states all sales are final, but you can always ask nicely. Your friend should have checked the specifications of your ipad before making the gift. -
Hi, I have Photoshop CS 6 Extended, but my laptop does not have a disk tray (acer aspire v5-573g) and I have the serial number, is there any way I can download this version of Photoshop I'm not sure what to do...
You can download photoshop cs6 from here:
http://helpx.adobe.com/x-productkb/policy-pricing/cs6-product-downloads.html -
I have adobe reader X. Is there no way to save, print or e-mail changes to a secured pdf? I've inputted changes and have digitally signed, but none of my edits seem to save?
By what kind of security I meant what is allowed and what is not allowed under the security tab that I mentioned in my last post?
You can look at that and see if it restricts what you are trying to do. If it does then yes, you need a version of Acrobat (and the password of course) to change it. -
How do I save and import my bookmarks from another hard drive? When I try to open the installed Firefox on the old drive, it (obviously) opens a browser from the new main drive, free of bookmarks. Is there a way I can save the bookmarks on the old drive without opening a browser?
The guts of my computer were rearranged and I got a new main hard drive. My old one is still in there and I can get stuff from it, but when I go to the Mozilla folder on the old one, I can't figure out if there's anything I can do to get all my bookmarks from that drive to my new one, where Firefox is newly installed.If you open Firefox then Firefox will always use the default profile folder as found via profiles.ini on your system drive.
You either need to import the file in your current default profile or copy the file to your current profile folder while Firefox is closed.
Firefox 3 stores the bookmarks and the browser history in [http://kb.mozillazine.org/places.sqlite places.sqlite] and no longer creates an HTML backup by default.
There are also (five) JSON backups in the bookmarkbackups folder within the Firefox profile folder.
You can either copy the file places.sqlite to your [http://kb.mozillazine.org/Profile_folder_-_Firefox Firefox Profile Folder] or import the most recent JSON backup from the bookmarkbackups folder of that old profile.
See:
http://kb.mozillazine.org/Backing_up_and_restoring_bookmarks_-_Firefox
http://kb.mozillazine.org/Transferring_data_to_a_new_profile_-_Firefox
See http://kb.mozillazine.org/Profile_folder_-_Firefox
"Application Data" in XP/Win2K and "AppData" in Vista/Windows 7 are hidden folders.
See http://kb.mozillazine.org/Show_hidden_files_and_folders
Go to: Control Panel > Folder Options > "View" tab > under "Hidden files and folders", select "Show hidden files and folders".
You may want to un-check the box "Hide extensions for known file types" to see the file extensions of all files. -
I recntly got a iphone and i gave my daughter my ipod and we only have one apple id, is there a way to seperate the two so I don't see her instant messages? or do we have to have seperate apple IDs?
Create a second Apple ID for a separate iCloud account. You can still share the Apple ID for iTunes purchases, but separate for the cloud.
-
I have always shared my apple ID & iTunes library with my daughter but now she is old enough to have her own. Is there a way to split my iTunes library with hers if she now has her own apple ID/library?
settings->store
there you change appleID
multiusing ios devices don't really works very well -
I have transferred my itunes from pc to new mac book pro. In the syncing of ipod have lost playlists. Is there a way of getting them of old pc library into itunes on mac. Seems to only allow me to do it song by song?
I have transferred my itunes from pc to new mac book pro. In the syncing of ipod have lost playlists. Is there a way of getting them of old pc library into itunes on mac. Seems to only allow me to do it song by song?
-
my pictures are not showing up on my iphone 4s and i do not have icloud set up is there any way ro fix this?
Pictures from where?
-
I had music that i copied from disks into itunes on another computer, I no longer have that computer. Is there a way to get that music back from itunes?
ThanksIf you failed to maintain a backup copy, then you would have to import the disks again.
-
Today I deleted an email services I no longer need. Now when I go to the notes app I no longer have any notes. Is there any way to get my notes back. I have the first iPad running iOS 5.1.1
Ah, well, then the notes are probably gone. Did you save any of the email from that account on your computer? The notes might be there if you did.
-
After syncing my iphone to my itunes on my pc, all the music on my phone is gone. I don't have a backup. Is there any way I can get them back?
If you had no other backup....NOPE! However, if you purchased your songs from iTunes, check out: iTunes Store - Finding Lost Music FAQ
Maybe you are looking for
-
Need help, unable to find my Serial Number
I recently moved to a new house, with all the ensuing hassles. Shortly after moving I decided to upgrade my computer to Windows 8. And in order to try and get rid of some old problems I only kept the private files and did a clean update. After (succe
-
Links in blog archive not working
Can anybody help me get more reliable performance from my iWeb archives page? http://web.mac.com/truthmaker/Site/Blog/Archive.html I am getting very frustrated with the Archives page for the blog I've created with iWeb. Often -- very, very often, the
-
Mail in Maverick crashes when I try to attach a file.
Each time I try to attach a file to an email in Maverick Mail crashes...I have fixed permissions and all the other recommended steps...nothing works???
-
Why does my iMovie shut down when trying to import videos
When I am trying to import video to my library my iMovie closes and I get a "iMovie quit unexpectedly". How can I fix this?
-
SO FUSTERATED PLEASE HELP!!!!
I keep getting a message to contact ITUNES supoport under payment type when I enter my credit card which is a visa card! I go to the web site but I do not understAND WHAT TO LOOK FOR! pLEASE HELP