• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

file access within package

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI - why am I getting an end of file exception when this is part of a package - works find when it is not part of a package. all advice apprecitated.

[Andrew: put the source code between [code] and [/code] UBB tags]
[ April 29, 2004: Message edited by: Andrew Monkhouse ]
 
Laura Williamson
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry sorted it, was being thick.
apols
Is RandomFileAccess the way to go with this ?
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Laura
Sure, RAF is ok. The only problem I see here is hard-coded path,
System.getProperty("user.dir") is better.
Btw could you post stack trace?
Regards
 
Laura Williamson
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok thanks. the only problem I have with system.getproperty is this:
I am working in a package suncertify.db. (with suncertify directly under c:/)
So running from the command line in the c:/ java suncertify.db.MyApp to run an application. So the system.getproperty is returning c:/ - which is not the full path to where the file is stored.
any advice?
thanks
 
Laura Williamson
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this seems kind of a stupid solution...

String dir = System.getProperty("user.dir");
String path = "suncertify//db//";
System.out.println (dir);
String file = "db-2x3.db";
File f = new File(dir + path + file);
 
Denis Spirin
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that you dont know from what directory your program will be run.
You may mention in userguide and documentation that dbfile must be in current working directory or something like that. Anyway if you want to hardcode dbpath, in this version your
program wont work on Windows (and this means authomatic failure).

Regards
[Andrew: edited code so that horizontal scrolling is not required to read the posts in this page]
[ April 29, 2004: Message edited by: Andrew Monkhouse ]
 
Laura Williamson
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok thanks u rule. it was working in windows though - are you thinking file separator causes probs? maybe wouldn't work in UNix?
// escapes the / in windows. but prob. this cause probs in unix.
anyway - so once i get all the data in i create record objects maybe using a column class, kind of make a schema? sorry might have bitten off more than i can chew here, never had major java project at work, only uni.
 
Laura Williamson
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how do i read the numeric vals stored in the header.
come out as | (thick black downwards line) in textpad.
reading/writing with dataoutputstream/datainputstream does not let me read them.
 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The values are bytes, not ascii so you'd expect them to appear in Notepad/TextPad as something strange.
Just read in the number of bytes you want and make the number up.
Steve
 
Laura Williamson
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry? make the number up? can you explain. maybe i've bitten off more than i can chew with this assignment
 
Denis Spirin
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as I know file separator on Windows 2000 / XP is "\", on Linux and Mac "/"
(I use Mac).
You should not try to "read" header in notepad. File is binary, so you should use
something like readInt(), readShort(), readFully() etc.
 
Laura Williamson
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
using readByte.
 
Laura Williamson
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok so
2 byte numeric, number of fields in each record
will require a readShort because short is two bytes, etc, etc.
ok i get it - i think.
i can see that this project is going to be quite a learning curve.
thanks for yr help.
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Laura,
Welcome to JavaRanch.
I have edited your post to put the code between [code] and [/code] UBB tags. Doing this ensures that indenting is preserved, which makes the code easier to read.
When you are writing your post, there are a number of buttons just below the edit pane, which will insert the tags for you, so you don't have to remember what they are.
If you would like to edit your original post so that you can see what I have done, you can click on the button that is just above your post.
This assignment may have a large learning curve, but I hope you stick with it. As you can see, there are lots of people willing to help.
Regards, Andrew
[ April 29, 2004: Message edited by: Andrew Monkhouse ]
 
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Concerning File Separators:
I've noticed that I can open a RandomAccessFile whose filename
is specified using the single forward slash like this on Windows
Professional 2000 with Sun JRE 1.5:
"C:/Project/MyDatabase001.db"
or
"C:\\Project\\MyDatabase001.db"
and in classes which extend JDialog, I'm able to enter the filename
into a textfield on Windows Professional 2000 with Sun JRE 1.5
in either of these two forms (both work, just as the two forms above
both work):
C:/Project/MyDatabase001.db
or
C:\Project\MyDatabase001.db
I have not tested this with Windows Professional 2000 with Sun JRE 1.4.
I'm not saying that one should not use the FileSeparator constant, I'm
only pointing out what I have noticed: that version 1.5 does seem to
not force the user to know the file separator for a given operating
system (which makes sense, since Java is not supposed to be bound
to a particular operating system's file system, under ideal circumstances).
Thanks,
Javini Javono
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Javini,
The problem with that is that you are relying on an undocumented feature of the particular JVM you are using. While it may work with your particular release of the JVM on MS Windows, there is no knowing what will happen if you change to a different release of the JVM or a different JVM vendor, or a different operating system.
The platform abstraction fields were put there for a purpose. You really should use them.
Regards, Andrew
 
This tiny ad will self destruct in five seconds.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic