-2

I've managed to learn how to read/write from/to a .txt file from an Arraylist in Java. But I'm struggling to do so from binary.

The Arraylist would be in the format of: String,String,String,String,String,String,String,String.

I was thinking of doing a .split() by the binary equivalent of a comma (00101100), but I'm completely stuck. Can anyone tell me the basic imports needed to read a binary file and then add it to the Arraylist. Thank you :)

my idea might be completely wrong so please suggest better methods :)

Lets call the Arraylist SD. Just because that's how I've set it up. Any more information please just comment!

JJ Wilson
  • 17
  • 4
  • Have you written a binary file? Because it certainly wouldn't look like `00101100` in a text editor. – Jacob G. Apr 18 '18 at 23:43
  • @JacobG I'm completely new to binary and that is why im asking for help! It basically needs to read a binary file and it to an arraylist – JJ Wilson Apr 18 '18 at 23:52
  • What exactly do you mean when you say "from **binary**"? Even `.txt` files are, in the end binary. Do you have a specific "binary" format in mind, or were you just looking to learn something different? – Kevin Anderson Apr 18 '18 at 23:56
  • @KevinAnderson I just got set it as an basic exercise and wanting to know more. It just says: load and save all student details to file (in binary/text format). The student details are categorised in the question as String,String,String,String,String,String,String,String (That's how they are in the arraylist). – JJ Wilson Apr 19 '18 at 00:06
  • @KevinAnderson so from your higher understanding and opinion - what do you think would be the best approach? – JJ Wilson Apr 19 '18 at 00:07
  • @KevinAnderson it specify binary files, so I'm presuming a binary file has to be read and taken in and added to the arraylist. – JJ Wilson Apr 19 '18 at 00:09
  • In the meantime, possibly look into [FileInputStream](https://docs.oracle.com/javase/7/docs/api/java/io/FileInputStream.html) and [FileOutputStream](https://docs.oracle.com/javase/7/docs/api/java/io/FileOutputStream.html). This question looks related: [How do i read in binary data files in java](https://stackoverflow.com/questions/36652944/how-do-i-read-in-binary-data-files-in-java) – chickity china chinese chicken Apr 19 '18 at 00:38
  • The term "binary/text" could mean just about anything and therefore means nothing. Unless your taskmaster has something more specific in mind, I'd say even a `.txt` file qualifies as "binary/text", So I'd either seek clarification from whomever has set you this assignment, or find someone else who gives clearer assignments. – Kevin Anderson Apr 19 '18 at 00:59

1 Answers1

0

Simply use .split(","); to read the values. The binary text file you are talking about is just a regular text file, from your comment

to file (in binary/text format).

Raymo111
  • 514
  • 8
  • 24
  • Hi from the question: load and save all student details to file (in binary/text format), i.e. your system should allow both binary AND text format files to be used. Would this not be a .bin file or is a text file with binary numbers? – JJ Wilson Apr 19 '18 at 00:23