error in seek() class

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • natie
    New Member
    • Oct 2010
    • 5

    error in seek() class

    I'm new in java and while I was working on a project which had DataInputStream s etc, my compiler show me this error:

    symbol : method seek(int)
    location: class java.io.DataInp utStream
    F.seek(0);

    I read in a forum that seek() is only for long types..
    Is it correct?

    what i'm going to do now?

    thanks
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    the DataInputStream does not have seek() method acording to the documentation


    are you thinking of RandomAccessFil e


    which does have a seek() method

    Comment

    • natie
      New Member
      • Oct 2010
      • 5

      #3
      oh thanks.. I understood it now I think better..
      and can I ask smthng more? in RandomAccess Files, do we have to use always seek method?

      and somthng more: for instance, the F.seek(0); /*if F is our file*/ goes us to the top of our file.. do we have to declare above our class something or not?

      Comment

      • horace1
        Recognized Expert Top Contributor
        • Nov 2006
        • 1510

        #4
        not if you sequentially access the file, when you open the file the first record read/written would be the first, etc etc
        You would use seek() if you need to randomly access it, i.e. move to a record without accessing all the records in between

        Comment

        • natie
          New Member
          • Oct 2010
          • 5

          #5
          if for example I have a a class which concludes a method in which I write something in a file, and another which searches for something specific in the same file, and the main class uses both of them. In the second method,do I have to use the seek method?
          hmm it's getting weird! :|

          Comment

          • horace1
            Recognized Expert Top Contributor
            • Nov 2006
            • 1510

            #6
            it all depends on what your specification is.
            If it is simple in that you write data to a file, close it, then open and read sequentially you don't need seek().
            However, if you are writing and reading randomly to different parts of the same file you will need to use seek() to a particular record or rewind (seek(0)) then sequentially search.
            What exactly do you need to do? I think you need to clarify this!

            Comment

            Working...