1.15.2 Creating your own custom file type

Discussion in 'Spigot Plugin Development' started by Xocky, Feb 2, 2020.

  1. How can you create your own file type and read/write it in java?
     
    • Like Like x 1
  2. File types are born in the vast lands of Atlantis when the Moon and the sun are perfectly aligned to shine onto the altar of the mighty windows; then you have to sacrifice a penguin to the mighty macintosh, and in the light of the shrine you will find that a new file type is born!

    Jokes aside, you'd read/write your file just as you would do with any other file
     
    • Funny Funny x 9
    • Winner Winner x 1
  3. A file extension is just an identifier. It doesn't do anything by itself. So just save the file as whatever.yourawesomeextension and it will be the same as saving it as whatever.txt
     
  4. Yes. You can open a JAR file as an image if it is in png format. File extension doesn't do anything except being more understandable for the user.
     
    • Agree Agree x 2
  5. Fun fact: Linux doesn't have a concept of file extensions
     
    • Informative Informative x 1
  6. Optic_Fusion1

    Resource Staff

    Fun fact: Not everyone uses linux
     
    • Agree Agree x 1
    • Optimistic Optimistic x 1
  7. I know - I was just trying to hint to OP that file extensions don't really mean anything, especially on Linux
     
    • Like Like x 1
  8. Optic_Fusion1

    Resource Staff

    Depends on the extension & program.
    For example i can create a .dat file, doesn't mean minecraft could use it unless that file PROPERLY followed the NBT format.

    TLDR; The extension, file content and program used matters a lot.
     
    • Like Like x 1
  9. *grabs popcorn*
     
    • Funny x 2
    • Like x 1
    • Agree x 1
    • Winner x 1
    • Informative x 1
  10. Optic_Fusion1

    Resource Staff

    Haha, i actually have popcorn somewhere, but dinner is being made :p
     
    • Optimistic Optimistic x 1
  11. Of course - however if I rename the .dat file to just "hello", and then edit minecraft to reflect the new path changes, then it'll still read it fine.

    And of course it must follow the NBT format - I never said otherwise. I said that the file extension doesn't change anything to do with how the file is read and how data is written to it, hence why Linux doesn't use them
     
  12. this is way off topic, can we stop?
     
  13. for writing to/from a file, it depends on the file format you want it to have. yml, json, whatever dat is technically called, standard txt, ect. you use specific methods of saving to and from a file. it depends on the format you want. if you want a simple txt read/writer, the Files java api has this for you already, or you can manually do it yourself with FileReader and FileWriter objects. a quick google of this would tell you more in depth explanations.
     
  14. Other fun fact: some apps use file extensions like .conf etc...

    It's not off-topic. We're explaining to the OP what is really file extensions ;)

    True. A file is just a collection of bytes. You can use a text format like json, yaml, etc... or use a "raw" format like NBT (Usually named foo.dat) which write directly bytes, int etc... in an OutputStream using a byte (NBTTagEnd's type id) to separe values