I know that this may seem like a re-occuring question, but I can't seem to find anyone who has asked this question in a very succinct manner. They always seem to beat around the bush, instead of clearly expressing themself.

Here is the situation:

I have an application called S.M.A.R.T. In this application it processes data(duh!). It stores data in both single and multi-dimensional arrays. I desire to store these data-filled arrays in a file, along with other elementary data types. And the file that I want to store it in, must end with the extension .smproj (as an example of course...it could be .happy for all I care :D).

I want my application to accomplish that, as well as to reopen the file and recognize the data in the file when it needs to retrieve it later, so that the data can be further processed.

I don't necessarily want code...just a heads up in the right direction please...Thank You

Dani AI

Generated

Useful follow-ups to the thread from and β€” short, practical checklist and cautions.

Java does not enforce file extensions: you can write a binary object stream (or any bytes) into a file named whatever you like, so a .smproj file can be a Java-serialized blob and will look unreadable in Notepad. (docs.oracle.com)

Quick pros/cons and safety notes: built-in Java serialization is the fastest path for Java-to-Java persistence, but it’s brittle across class evolution and dangerous with untrusted input. Plan for versioning (explicit serialVersionUID or a custom serial form) and never deserialize untrusted streams without strict allow-lists or signatures β€” deserialization has been a common attack vector. If you need long-term stability, consider stable on-disk formats (JSON/CBOR, Protocol Buffers, flat files) or an explicit migration layer. (docs.oracle.com)

A recommended file layout and write/read pattern (keeps the extension you want, makes files identifiable, and supports upgrades):

write magic bytes (eg "SMPR"), write int version;
serialize your object graph into a byte[] (or use JSON/protobuf);
optionally gzip/encrypt/sign the byte[]; then write it to disk.

On load: validate magic + version, verify signature if present, then decompress/decrypt and deserialize with an allow-list or migration logic. Also treat sensitive fields as transient or encrypt them before writing. (wiki.sei.cmu.edu)

About associations / deployment (answering the Web Start question): associating a custom extension with your app is an OS task β€” Windows uses registry/Default Programs APIs, macOS uses CFBundleDocumentTypes in Info.plist, and Linux desktops use .desktop/MIME registration (freedesktop.org). For distributing Java apps today, Java Web Start was deprecated and removed from Oracle JDK 11; options are packaging as native installers (use jpackage) or using OpenWebStart for JNLP compatibility. Use the platform installer to register your .smproj type so double-click launches your app. (learn.microsoft.com)

Short next steps: pick format (fast: Java serialization; safe/stable: JSON/protobuf), add a 4-byte magic + version, sign/encrypt if needed, and create native installers (jpackage) to register file associations.

Recommended Answers

All 4 Replies

Oh..and the contents of my file: File.smproj, should not be readable in a text editor like Notepad. I looked up using serialization, but that requires using a .ser file extension, which is not permissable for me to do. Any further suggestions please?

Serialization is a good answer. Open an ObjectOutputStream to a file with any name and extension you want. Java IO won't care about the extension.

Okay, thank you, I'll give it a shot.

And so you are saying that basically..all I have to do is save the file with whatever extension I want it to be?

I have one more thought. As it relates to application and file association, namely triggering my application to open the file when it is opened...um..how would I accomplish this please?

I remember seeing something about Web Start is that a good lead to follow?

Yes, just avoid any extension that's already associated with a well-known application. Associating an application with an extension to trigger the app when a file is clicked: that's an OS function - details of how to depend on which version of which OS.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.