Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Files between Java and C#  (Read 1802 times)
0 Members and 1 Guest are viewing this topic.
Offline nhmllr

Senior Devvie

Medals: 1
Projects: 3

slow and steady...

« Posted 2013-01-14 03:01:51 »

This is not gaming related. For various reasons, I need to get some data from a Java application to a C# application. I have very little C# experience and am learning that now. By "data," I mean a list of about a thousand doubles. What is the best file type to save this as that can be reopened in a C# application? Text files? Wouldn't that take up a little too much space? Although if it's only about 5 or so times the space I wouldn't mind so much.

This is very nebulous at the moment. What file type would you use for this task and why?

Offline sproingie

JGO Kernel

Medals: 202

« Reply #1 - Posted 2013-01-14 03:30:53 »

The textual representation of a double at maximum possible precision is something like 56 bytes.  Times a thousand, let's make it 1024, and you're talking 56K.  Store it as binary and it's 8K.  Tiny in either case.  Optimize for your use case, cuz it's not going to take any real space.

I personally would just use a text file.

Offline LunaticEdit

Senior Devvie

Medals: 8
Projects: 1

« Reply #2 - Posted 2013-01-14 03:33:51 »

Agreed, just dump the thing into file with each number separated by new lines. Would be nothing to write 'em out, and nothing to read 'em in (double.parse(strval) in c#).

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nhmllr

Senior Devvie

Medals: 1
Projects: 3

slow and steady...

« Reply #3 - Posted 2013-01-14 04:44:54 »

Yeah... That's kinda the response I was expecting to get.

Okay, thanks!
Offline jonjava
« Reply #4 - Posted 2013-01-14 07:19:23 »

All "data" is bytes. When you're writing or reading any data you're always dealing with bytes.

A double in java is 8 bytes. A double in c# is also 8 bytes. (8 bytes = 64 bits).

What is the best file type to save this as that can be reopened in a C# application?

This is fundamental misconception. There are no file types. There's no such thing as a "text file" or an "mp3 file" etc. They are just collections of bytes in memory.

You can give your 'collection of bytes' (file) any kind of name you want. This name is used by the operating system to locate the collection of bytes on the hard disk.

The name has nothing to do with the data inside the file.

Then why do some file names have ".txt" or ".pdf" at the end? The only reason here is that the Operating System can look at the name and by looking at the end it will decide what program it will open that file with (Since you almost always have a default program for certain files).

If the OS doesn't recognize the file name it will ask you to find a program to open it with.

If you open an mp3 file with a text editor you will see what the bytes that makes the mp3 file would look like if the bytes were interpreted as text.

The only difference between a "txt file" and an "mp3 file" is how the bytes are ordered.

So in this case I'd probably make up my own "file type" (schematic of how the bytes are ordered).

If I know how the bytes are ordered, as I should since I myself came up with it, I can read (interpret) and write it willy nilly.

So if I'd want to save thousands of doubles, I'd probably at the beginning of the file stick an int (4bytes = 32bits) to tell how many doubles this file holds. Then I'd stick in all the doubles after each other.


Doing it as a "txt file" only means that you will convert your bytes into an order that your ordinary text editor can interpret correctly.

The minimum bytes needed to represent a character (eg: 'a', '.' or '4') is 1 byte (ASCII charset).

Click to Play

You would need to convert each double into a String of characters. As sproingie pointed out a double represented as a string would take approximately 56 characters or 56 bytes instead of the 8 bytes that actually make up the data of a double.

Then to make it back into a double in c# you would have to interpret/convert these strings into a double again.

All of this unnecessary encoding and decoding will make your file about 56/8=7 times bigger and possibly lose precision along the way.

The only benefit/disadvantage of doing this is you can open the file in a text editor and see an approximation of the doubles as a string.

Pages: [1]
  ignore  |  Print  

EgonOlsen (77 views)
2018-06-10 19:43:48

EgonOlsen (57 views)
2018-06-10 19:43:44

EgonOlsen (77 views)
2018-06-10 19:43:20

DesertCoockie (259 views)
2018-05-13 18:23:11

nelsongames (157 views)
2018-04-24 18:15:36

nelsongames (156 views)
2018-04-24 18:14:32

ivj94 (897 views)
2018-03-24 14:47:39

ivj94 (161 views)
2018-03-24 14:46:31

ivj94 (810 views)
2018-03-24 14:43:53

Solater (174 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!