954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

JList item write and read in txt file

Helo every one.
i m workin with jlist and i got several items in jlist i want to store this items into txt file and read it later. is it possible to do it? any help will be apprict. hop i explained wel ... thx

Attachments Capture.JPG 19.9KB
emint
Junior Poster in Training
60 posts since Jun 2009
Reputation Points: 10
Solved Threads: 4
 

Yes; use Serializable. (Assuming all you want to do is save your JList and restore it when you restart, you can use Serializable to save your Objects, then you can easily restore them into the JList).

BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
 

Thank you for ur reply. can u pls explain bit more bout it. that would be helpful thanks

emint
Junior Poster in Training
60 posts since Jun 2009
Reputation Points: 10
Solved Threads: 4
 

U can ofcourse... i have sample program here that will write file in text its up to you how you gonna revise it..

package cs344;
import java.io.*;

public class WriteFile
{
public static void main (String [] args)throws IOException
{
String filename;
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter filename");
filename = input.readLine();

System.out.println("Enter data to write to" + filename);
System.out.println("Type @ to end");

FileOutputStream fos = null;

try
{
fos = new FileOutputStream(filename);
}catch(FileNotFoundException e)
{System.out.println("File cannot be openned for writing... ");}

try
{
boolean done = false;
int data;

do
{
data = input.read();
if((char)data == '@')
done = true;
else
fos.write(data);
}while(!done);
}catch(IOException er){System.out.println("Error reading from file");}
}
}

catubig37
Newbie Poster
2 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
 

Just google Serializable. Why would I bother to rewrite something that already has plenty of resources available? Especially when the available resources are written by people with more knowledge of the concept than I have?

If you want specific answers, ask specific questions. If you want me to write an article about Serializable, go away.

BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You