Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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 701 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?

Thanks
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).

Quote
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.

[int][double][double][double]


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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

rwatson462 (36 views)
2014-12-15 09:26:44

Mr.CodeIt (29 views)
2014-12-14 19:50:38

BurntPizza (61 views)
2014-12-09 22:41:13

BurntPizza (98 views)
2014-12-08 04:46:31

JscottyBieshaar (58 views)
2014-12-05 12:39:02

SHC (74 views)
2014-12-03 16:27:13

CopyableCougar4 (76 views)
2014-11-29 21:32:03

toopeicgaming1999 (137 views)
2014-11-26 15:22:04

toopeicgaming1999 (127 views)
2014-11-26 15:20:36

toopeicgaming1999 (37 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org 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‑gaming.org
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!