Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How do you store attributes for a java text file in the file itself?

  1. #1
    Member GoodbyeWorld's Avatar
    Join Date
    Jul 2012
    Location
    Hidden command post deep within the bowels of a hidden bunker somewhere under a nondescrip building
    Posts
    161
    My Mood
    Stressed
    Thanks
    14
    Thanked 25 Times in 25 Posts

    Question How do you store attributes for a java text file in the file itself?

    I was thinking of using the UserDefinedFileAttribute class and stuff to do this, but I don't know if what I want is even possible.

    Can you store attributes such as Font and text color and stuff inside a .txt file itself?

    If another text program that opens the file you made or modified inside such an editor, will it ruin the attributes and set them to null?

    (i.e. if I pull this off in a java notepad, if I ever opened the file that had the attributes with some other editor such as Windows Notepad, would the other editor mess with the attributes, hence possibly ruining them?)

    The UserDefinedFileAttribute route involves a lot of strange interfaces (ones I don't have a clue what they do) and I'm wondering if I'm going the wrong route.


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,469
    My Mood
    Grumpy
    Thanks
    0
    Thanked 158 Times in 149 Posts

    Default Re: How do you store attributes for a java text file in the file itself?

    if you want to save the state of an object you can make the class implement Serializable and then save using ObjectOuputStream.
    Improving the world one idiot at a time!

  3. The Following User Says Thank You to Junky For This Useful Post:

    GoodbyeWorld (November 14th, 2013)

  4. #3
    Member GoodbyeWorld's Avatar
    Join Date
    Jul 2012
    Location
    Hidden command post deep within the bowels of a hidden bunker somewhere under a nondescrip building
    Posts
    161
    My Mood
    Stressed
    Thanks
    14
    Thanked 25 Times in 25 Posts

    Default Re: How do you store attributes for a java text file in the file itself?

    It may have many different properties. I'm not sure if I should be focusing on it as a "property" or as a "state".

    How would this info be saved in the file, and hence be able to be read in as an attribute of the file/document (it has to be stored in an actual file or as an attribute that can be accessed from the File object, which could already exist and need not be created anew every time) and applied to the JTextArea in a notepad? I mean, how would you store a font of a JTextArea as a file (which contains the text in the JTextArea) and then read that font attribute and use that read attribute to set the font when the file is loaded up?

  5. #4
    Member GoodbyeWorld's Avatar
    Join Date
    Jul 2012
    Location
    Hidden command post deep within the bowels of a hidden bunker somewhere under a nondescrip building
    Posts
    161
    My Mood
    Stressed
    Thanks
    14
    Thanked 25 Times in 25 Posts

    Default Re: How do you store attributes for a java text file in the file itself?

    Any ideas?

Similar Threads

  1. Java code Split text file into multiple text file
    By jayraj in forum What's Wrong With My Code?
    Replies: 26
    Last Post: April 19th, 2013, 06:14 AM
  2. How do I copy a simple text-file to a new text-file?
    By get703 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: December 5th, 2012, 09:59 PM
  3. Conversion of any image file to text file in Java...'
    By suyog53 in forum File I/O & Other I/O Streams
    Replies: 17
    Last Post: September 23rd, 2012, 08:37 AM
  4. Created a Random Access File that saves gibberish to a text file
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 21st, 2012, 11:45 AM
  5. java program to copy a text file to onother text file
    By francoc in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: April 23rd, 2010, 03:10 PM