|
||||||
| Java Help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
Can anybody tell me how can contents of JTable be written into txt file and read from txt file back to new JTable using IO streams.Please help me if anybody knows. Thanks I have a table(Xenon) already populated with some data and i want when a certain button is clicked, data in the table to be read and writen in a file (myXenon.txt) My code is as below: Code:
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
DefaultTableModel model = (DefaultTableModel) Xenon.getModel();
try {
File f = new File("myXenon.txt");
boolean success = f.createNewFile();
if (success) {
//File did not exist and was created
}
else {
//File already exists
}
BufferedWriter out = new BufferedWriter(new FileWriter(f));
this. = Xenon.readData(ROWS_QUANTITY, COLUMNS_QUANTITY);
/*At this point the table is supposed to be read and the data writen in the file myXenon.Anybody with an idea? */
out.write();
out.close();
System.out.println("The file myXenon.txt has been created and updated in the current directory");
}
catch (IOException e) {
}
try {
Vector data = new Vector();
String aLine;
FileInputStream fis = new FileInputStream("myXenon.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
while ((aLine = br.readLine()) != null) {
// create a vector to hold the field values
Vector row = new Vector();
// tokenize line into field values
StringTokenizer st = new StringTokenizer(aLine, "|");
while (st.hasMoreTokens()) {
// add field to the row
row.addElement(st.nextToken());
}
System.out.print(data);
// add row to the model
model.addRow(row);
}
br.close();
fis.close();
} catch (IOException e) {
}
}
Last edited by Manfrizy; 12-04-2008 at 02:13 AM.. Reason: Problem siplified |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| C# Tutorial: Writing Text Files | Xav | CSharp Tutorials | 44 | 06-02-2009 06:05 AM |
| Saving and reading a Text file | Sparky | Pascal/Delphi | 11 | 12-03-2008 10:27 AM |
| What mode should i use at fopen()? r, r+, w+b??? | tirengarfio | C and C++ | 3 | 08-13-2008 11:06 PM |
| Tutorial: Visual Studio 2008 C# Compressing | Jordan | CSharp Tutorials | 0 | 05-13-2008 04:52 PM |
| Issue writing to file: pointer to a class which contains pointers to other classes | Sheemer | C and C++ | 0 | 08-21-2007 01:17 AM |
Algorithms and Data Structures
Programming Language Popularity
Code Collaboration
Podnet IRC Network
AmpHosted
Goal #1: 1,000 Blogs
Goal #2: 1,000 Wiki Pages
Goal #3: 300,000 Posts
Goal #4: 20,000 Threads
Done: 30%, 23%, 55%, 75%