Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. noob Needs help with File Handles and VM RAM

noob Needs help with File Handles and VM RAM

Scheduled Pinned Locked Moved Java
databasehelpjavadata-structuresquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TylerD75
    wrote on last edited by
    #1

    I'm not sure if this is the right forum, as this might be related to either NFS or the underlying FS, but anyways... I'm going through a number of Folders to find subfolders and the files in those subfolders:

    Media_Folder1
    |-> subfolder_1 -> File1, file2, etc...
    |-> subfolder_2 -> File1, file2, etc...
    Media_Folder2
    |-> subfolder_1 -> File1, file2, etc...
    |-> subfolder_2 -> File1, file2, etc...
    ...

    I use the following code:

    File rFolder = new File("/Media_Folder/");
    File[] subFolderArray = rFolder.listFiles();
    for (int i = 0; i < subFolderArray.length(); i++) {
    if (subFolderArray[i].isDirectory()) {
    // For each subfolder I'll enter it, and add each file to a custom file class array
    File[] tmpFolderContent = subFolderArray[i].listFiles();
    for (int i2 = 0; i2 < tmpFolderContent.length(); i2++) {
    myCustomFileClass tmpCustFile = new myCustomFileClass(tmpFolderContent[i2].getPath());
    }
    .... // etc...

    The problem is that the code above (or a bit more complicated version) is working fine, until a certain point. Then suddenly the tmpFolderContent array gives a nullpointer exception. 1. The code above (...and then some) creates a MediaObject that contains a StringArray that holds names of all subfolders. 2. Then the code goes through all those subfolders to create a CUSTOM FileObject array (Not the regular java.IO.File class, but a custom one that holds only enough info to create a new java.io.File object). The Custom FileObject ARRAY holds the filename and path of all files in all subfolders. 3. The number of files in each subfolder is never more than 25-30, and the number of subfolders is never more than 10, but the number of MediaObjects is fairly large (450++). There are some ways I can go around this problem (Like add each object to the database right after it's creation [which is what I want anyways, although I want to do something more with the objects before I do this], but this means creating the objects, store them in DB, read them from db and then change them accordingly). But I'd rather know what is causing this problem, so I know WHY I need to do it that way ;). The strange thing is that it appears on the same media folder, and the exact same subfolder each time. If I skip this folder, it happens on the next subfolder. So something is reaching it's limit. I've also tried running the above code on ONLY the failing folder, and then it

    R N 2 Replies Last reply
    0
    • T TylerD75

      I'm not sure if this is the right forum, as this might be related to either NFS or the underlying FS, but anyways... I'm going through a number of Folders to find subfolders and the files in those subfolders:

      Media_Folder1
      |-> subfolder_1 -> File1, file2, etc...
      |-> subfolder_2 -> File1, file2, etc...
      Media_Folder2
      |-> subfolder_1 -> File1, file2, etc...
      |-> subfolder_2 -> File1, file2, etc...
      ...

      I use the following code:

      File rFolder = new File("/Media_Folder/");
      File[] subFolderArray = rFolder.listFiles();
      for (int i = 0; i < subFolderArray.length(); i++) {
      if (subFolderArray[i].isDirectory()) {
      // For each subfolder I'll enter it, and add each file to a custom file class array
      File[] tmpFolderContent = subFolderArray[i].listFiles();
      for (int i2 = 0; i2 < tmpFolderContent.length(); i2++) {
      myCustomFileClass tmpCustFile = new myCustomFileClass(tmpFolderContent[i2].getPath());
      }
      .... // etc...

      The problem is that the code above (or a bit more complicated version) is working fine, until a certain point. Then suddenly the tmpFolderContent array gives a nullpointer exception. 1. The code above (...and then some) creates a MediaObject that contains a StringArray that holds names of all subfolders. 2. Then the code goes through all those subfolders to create a CUSTOM FileObject array (Not the regular java.IO.File class, but a custom one that holds only enough info to create a new java.io.File object). The Custom FileObject ARRAY holds the filename and path of all files in all subfolders. 3. The number of files in each subfolder is never more than 25-30, and the number of subfolders is never more than 10, but the number of MediaObjects is fairly large (450++). There are some ways I can go around this problem (Like add each object to the database right after it's creation [which is what I want anyways, although I want to do something more with the objects before I do this], but this means creating the objects, store them in DB, read them from db and then change them accordingly). But I'd rather know what is causing this problem, so I know WHY I need to do it that way ;). The strange thing is that it appears on the same media folder, and the exact same subfolder each time. If I skip this folder, it happens on the next subfolder. So something is reaching it's limit. I've also tried running the above code on ONLY the failing folder, and then it

      R Offline
      R Offline
      Reagan Conservative
      wrote on last edited by
      #2

      Just a thought, but I think you may need to create new objects for both subFolderArray and tmpFolderContent before you make an assignment to them. You can't go past the end of the array since Java will take care of that sizing of the array for you.

      AF Pilot

      1 Reply Last reply
      0
      • T TylerD75

        I'm not sure if this is the right forum, as this might be related to either NFS or the underlying FS, but anyways... I'm going through a number of Folders to find subfolders and the files in those subfolders:

        Media_Folder1
        |-> subfolder_1 -> File1, file2, etc...
        |-> subfolder_2 -> File1, file2, etc...
        Media_Folder2
        |-> subfolder_1 -> File1, file2, etc...
        |-> subfolder_2 -> File1, file2, etc...
        ...

        I use the following code:

        File rFolder = new File("/Media_Folder/");
        File[] subFolderArray = rFolder.listFiles();
        for (int i = 0; i < subFolderArray.length(); i++) {
        if (subFolderArray[i].isDirectory()) {
        // For each subfolder I'll enter it, and add each file to a custom file class array
        File[] tmpFolderContent = subFolderArray[i].listFiles();
        for (int i2 = 0; i2 < tmpFolderContent.length(); i2++) {
        myCustomFileClass tmpCustFile = new myCustomFileClass(tmpFolderContent[i2].getPath());
        }
        .... // etc...

        The problem is that the code above (or a bit more complicated version) is working fine, until a certain point. Then suddenly the tmpFolderContent array gives a nullpointer exception. 1. The code above (...and then some) creates a MediaObject that contains a StringArray that holds names of all subfolders. 2. Then the code goes through all those subfolders to create a CUSTOM FileObject array (Not the regular java.IO.File class, but a custom one that holds only enough info to create a new java.io.File object). The Custom FileObject ARRAY holds the filename and path of all files in all subfolders. 3. The number of files in each subfolder is never more than 25-30, and the number of subfolders is never more than 10, but the number of MediaObjects is fairly large (450++). There are some ways I can go around this problem (Like add each object to the database right after it's creation [which is what I want anyways, although I want to do something more with the objects before I do this], but this means creating the objects, store them in DB, read them from db and then change them accordingly). But I'd rather know what is causing this problem, so I know WHY I need to do it that way ;). The strange thing is that it appears on the same media folder, and the exact same subfolder each time. If I skip this folder, it happens on the next subfolder. So something is reaching it's limit. I've also tried running the above code on ONLY the failing folder, and then it

        N Offline
        N Offline
        Naruki 0
        wrote on last edited by
        #3

        Your program will throw away every tmpCustFile object you create. Is this really what you intended? Also, I think your //etc. part chopped off some important bits. Also, why did you ignore standard naming procedures? myCustomFileClass should be MyCustomFileClass, to remind you that it's a class, not an instance. You said:

        TylerD75 wrote:

        At first I thought it was the FileArray that had reached its end, but it has room for a lot more (I amped it up after hitting this problem). Then I thought it could be the MediaObjectArray that had reached it's end, but after increasing it nothing changed.

        What are the two classes you mention? I did not see those anywhere in your code snippet. From your words, you are storing objects somewhere. From your code, you are not. Please fix one or the other and maybe we can give a better answer.

        Don't let my name fool you. That's my job.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups