-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremains.txt
More file actions
96 lines (76 loc) · 3.31 KB
/
remains.txt
File metadata and controls
96 lines (76 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
String filePath = "C:\\Users\\Desktop\\table.txt";
File file = new File(filePath);
try {
BufferedReader br = new BufferedReader(new FileReader(file));
// get the first line
// get the columns name from the first line
// set columns name to the jtable model
String firstLine = br.readLine().trim();
String[] columnsName = firstLine.split(",");
DefaultTableModel model = (DefaultTableModel)jTable1.getModel();
model.setColumnIdentifiers(columnsName);
// get lines from txt file
Object[] tableLines = br.lines().toArray();
// extratct data from lines
// set data to jtable model
for(int i = 0; i < tableLines.length; i++)
{
String line = tableLines[i].toString().trim();
String[] dataRow = line.split("/");
model.addRow(dataRow);
}
} catch (Exception ex) {
Logger.getLogger(TextFileDataToJTable.class.getName()).log(Level.SEVERE, null, ex);
}
Buffered Writer method to write string in txt..
String= "Save"
try{
BufferedWriter writer = new BufferedWriter(new FileWriter());
Writer.write(String);
Writer.close();
}
catch(IOException e)
{
}
input file from txt (irrelevant)
int n;
try {
BufferedReader inputFile = new BufferedReader(new FileReader("inventory.txt"));
numberEntries = Integer.valueOf(inputFile.readLine()).intValue();
if (numberEntries!= 0)
{
for(int i = 0 ;i< numberEntries;i++)
{
myInventory[i] = new InventoryItem();
myInventory[i].description = inputFile.readLine();
myInventory[i].location = inputFile.readLine();
myInventory[i].serialNumber = inputFile.readLine();
myInventory[i].marked =Boolean.valueOf(inputFile.readLine()).booleanValue();
myInventory[i].purchasePrice = inputFile.readLine();
myInventory[i].purchaseDate = inputFile.readLine();
myInventory[i].purchaseLocation = inputFile.readLine();
myInventory[i].note = inputFile.readLine();
myInventory[i].photoFile = inputFile.readLine();
}
}
n = Integer.valueOf(inputFile.readLine()).intValue();
if (n!= 0)
{
for (int i =0 ;i<n;i++)
{
locationComboBox.addItem(inputFile.readLine());
}
}
}
catch( Exception ex)
{
numberEntries = 0;
}
if (numberEntries == 0)
{
newButton.setEnabled(false);
clearButton.setEnabled(false);
//nextButton.setEnabled(false);
//previousButton.setEnabled(false);
printButton.setEnabled(false);
}