i am creating a text editor using java swings concept
this is the code i am using to save a file

jfr.setTitle(fname.getName());
FileOutputStream fop=new FileOutputStream(fname);
fop.write(jta.getText().getBytes());
fop.flush();
fop.close();

where fname is the name given in save file chooser bye the user
jta is the text pane in which the text to be saved...
my problem is that it is saving the text but not the font style,color,etc...

how to do it .. i am stuck here,please help me...

In what kind of file are you saving it?

i am using .c,.cpp,.java,.txt

If you are saving the text area to one of these files then they don't have fonts and sizes. That is up to the editor you are using to view the file.
.txt for example doesn't have colors.

i am typing some content with some styles and saving it,when i open it again i am unable to see the font styles which i have specified to them.

i am typing some content with some styles and saving it,when i open it again i am unable to see the font styles which i have specified to them.

That is because you are not saving the style. How are you suppose to see it?
You can try to create a separate file,for each text file, in which you will save specific information of the style. When you open the text file, also read the "style" file and adjust the fonts accordingly

i am new to java programming,can u say me how to create a separate file,for each text file, in which you will save specific information of the style. When you open the text file, also read the "style",,please??

In the same way you are saving and reading the file your are using now.
Only this time the other file will have data like:

color=255,0,0
// or color=red
font=5

And others. When you read the file with the text, you will also read the second file. Take the data and apply the style.

You should use BufferedReader in order to read the second file line by line. You will also use the String class to separate the name from the values:
color=red

For the file name, if the text file is called something like:
file.txt, then you can have the other called: file_style.stl

You could use an HTMLDocument as the document model for a JTextPane, then you can easily read/write the formatted content from/to .html files.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.