user63904
user63904

Reputation:

Using Java, what's the simplest method of writing a file to disk in a format that is easily readable by other applications

I've been asked to "write a file to disk in a format that is easily readable by other applications. There is no requirement for the file to be human readable". The data to be written to file is a combination of integer, string and date variables.

I can't quite figure out what the aim of this question is and what the correct answer should be.

What are the core considerations to be made in order to write a file to disk in a format that is easily readable by other applications (using the simplest possible method).

No this is not homework.

Upvotes: 2

Views: 210

Answers (3)

Ted Hopp
Ted Hopp

Reputation: 234817

This is a pretty vague requirement. If the other applications also written in Java, then Java serialization may be the best approach.

EDIT: @leftbrain — In answer to your comment, I think I would lean toward XML; it was designed to support basic interoperability among applications. The three kinds of data mentioned (integer, string, and date) can generally be represented exactly with no special tricks and there is good support for XML processing across most programming languages. However, each data type (in the abstract) can present challenges. I would have asked the following:

  1. What range of integer values need to be supported?
  2. What assumptions (if any) can be made about the string data? Does the full Unicode character set need to be supported?
  3. What range of dates, and what calendar systems, need to be supported?
  4. Is there a well-defined structure to the data?
  5. Is the performance (in terms of time and/or memory) of the write or read operation an issue? What does "easily readable" mean?

Upvotes: 2

Peter Lawrey
Peter Lawrey

Reputation: 533590

What the interviewer is looking for is to find out what experience you have in this area or what you might consider in implementing such a solution. Its and open ended question which has no right answer, it rather depends on the requirements.

Some suggestions use serialization of a data structure. Here a few http://code.google.com/p/thrift-protobuf-compare/wiki/Benchmarking

Use an SQL or NoSQL database. Here are some NoSQL databases. http://nosql-database.org/

Write the data to disk using DataOutputStream (IO), heap or direct ByteBuffers or memory mapped files. This can work well for simple cases like the one suggested in the question. As you requirements get more complicated, you might consider other options.

Upvotes: 1

Tom
Tom

Reputation: 4180

If you need to support multiple languages you can use xml.

Upvotes: 0

Related Questions