Results 1 to 16 of 16
  1. #1
    fogus is offline Member
    Join Date
    Mar 2008
    Posts
    43
    Rep Power
    0

    Default [SOLVED] Making a new folder, reading an entire file in one block read

    Hello,

    I am working on a new database indexing structure (to index a heap file). I have a need to create folders in which to store various index files.

    Secondly, I need to be able to read my files (files, NOT folders) in as few hard disk head movements as possible. I need to pull them into memory and then execute a linear search on them, but I do not want to read them line by line if this would cause n reads for a file containing n lines.

    Thanks,

  2. #2
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    Use
    new File("");
    to solve that problem

  3. #3
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    12

    Default

    Use a FileInputStream as the source object of a Buffered InputStream.

    Java Code:
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(...yoiur file name...));

  4. #4
    fogus is offline Member
    Join Date
    Mar 2008
    Posts
    43
    Rep Power
    0

    Default

    Quote Originally Posted by Webuser View Post
    Use
    to solve that problem
    Thanks.

    If that is how I make a new folder, then how do I make a new file?
    ~fogus

  5. #5
    fogus is offline Member
    Join Date
    Mar 2008
    Posts
    43
    Rep Power
    0

    Default

    Quote Originally Posted by toadaly View Post
    Use a FileInputStream as the source object of a Buffered InputStream.

    Java Code:
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(...yoiur file name...));
    Sounds good. So that grabs the whole file in one go? And then I can access it one line at a time? Nice.
    ~fogus

  6. #6
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    try it...
    Java Code:
    File f=new File("folder_1");
      f.mkdir();

  7. #7
    fogus is offline Member
    Join Date
    Mar 2008
    Posts
    43
    Rep Power
    0

    Default

    OK, I will, for sure.

    Another question: does anyone know how to make a "folder" structure within a single file ("single file" as in one .dat file in windows, for example) that can be accessed one "file" at a time? Is there a module to do something like that?

    Cheers,
    ~fogus

  8. #8
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    12

    Default

    You can create zip and jar files in Java. These can have an embedded directory structure. Is that what you mean?

  9. #9
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    Quote Originally Posted by toadaly View Post
    You can create zip and jar files in Java. These can have an embedded directory structure. Is that what you mean?
    yeah ) It is quite good way as Jar file creation. Pack your project there. And there ia a code way to get data out the jar file by Java )

  10. #10
    fogus is offline Member
    Join Date
    Mar 2008
    Posts
    43
    Rep Power
    0

    Default

    Well, what I am trying to do is create a new indexing method for a database (where records are stored in an unordered fashion in a heap file). My new structure is a mix between a hash table and a tree. It is extremely simple, easy to implement, and (I believe) efficient.

    Perhaps all I need is more control over how my files are read and written. I need some kind of way to write to a file without having to shift all the contents around. My index file has to persist on the hard drive through program restarts.

    Imagine this: you have a B+ tree index and you want to write it to the hard drive. How do you do it? I becha that if you can answer that question with sufficient detail, I will be able to figure out how to make my new structure persist.

    Cheers,
    ~fogus

  11. #11
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    you can put all resources right into your jar file in a folder structure you need and then sinply get out the recources you need to. But there may cause a problem with jar in the case you need to input the data (as db may should) :(
    What client you want to use. Is it an applet or an dt application?

  12. #12
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    12

    Default

    Quote Originally Posted by fogus View Post
    Perhaps all I need is more control over how my files are read and written. I need some kind of way to write to a file without having to shift all the contents around.
    Serialize in memory, and then write out to disk as a byte array. Don't use the file system as RAM, and you should be ok.

  13. #13
    fogus is offline Member
    Join Date
    Mar 2008
    Posts
    43
    Rep Power
    0

    Default

    "Serialize in memory"

    That sounds cool, but I don't know how to do it. (sorry, I'm a beginner)
    ~fogus

  14. #14
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    12

    Default

    Rather than writing directly to a file, write to a byte array. Then write the byte array to the file. If you explain a little more about how you're doing it with files, we can explain how to do it in memory.

  15. #15
    fogus is offline Member
    Join Date
    Mar 2008
    Posts
    43
    Rep Power
    0

    Default

    I think my problem is not that I cannot build the objects that I need in memory; it is that I do not know how to make those objects persist across program restarts.

    I need to have my index structure (think B+ tree) saved to a file so that it does not vaporise when I shutdown my program.

    I have made a binary tree before, and that was all well and good, but every time I needed to use it for an index I would have to rebuild it (because it disappeared last time I shut the program down).

    The other thing is, I can only assume an arbitrarily large hard drive, not RAM. I would much rather store my index structure on the hard disk (hence the similar structure to B+ trees, structures designed for a minimum of disk reads). Does anyone know how to make a B+ index in Java? I can't think of a way to make one persist. Where do I store the leaves? Do I need a lot of separate files or can I use one single large file?
    ~fogus

  16. #16
    fogus is offline Member
    Join Date
    Mar 2008
    Posts
    43
    Rep Power
    0

    Default

    Has anyone built a persistent B+ tree that is simple enough to explain the workings of to me?
    ~fogus

Similar Threads

  1. Replies: 2
    Last Post: 02-20-2009, 07:13 AM
  2. Replies: 0
    Last Post: 02-11-2009, 09:53 AM
  3. Replies: 5
    Last Post: 10-17-2008, 02:13 PM
  4. Making arrays by reading user input
    By apfroggy0408 in forum New To Java
    Replies: 23
    Last Post: 04-30-2008, 01:23 AM
  5. Replies: 1
    Last Post: 08-08-2007, 01:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •