Professional Documents
Culture Documents
import java.awt.*;
import java.awt.event.*;
import java.io.*;
add(b1);
add(t1);
add(t2);
add(l1);
add(l2);
add(q1);
setSize(500, 500);
setTitle(" 21BCM075 FILE SPLITTER");
setLayout(null);
setBackground(Color.yellow);
b1.setBackground(Color.orange);
setVisible(true);
b1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
String path = t1.getText();
BufferedReader r = new BufferedReader(new
FileReader(path));
String file = "i";
int poll = 1;
int entire = 0;
int n = Integer.parseInt(t2.getText());
while (true) {
PrintWriter h = new PrintWriter(new File("student_" +
poll + ".txt"));
for (int i = 0; i < n; i++) {
file = r.readLine();
if (file == null) {
break;
} else {
h.write(file);
h.write("\n");
h.flush();
}
entire++;
}
if (file == null) {
break;
}
poll++;
h.close();
}
r.close();
} catch (Exception z) {
System.out.println(z);
}
}
});
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}
OUTPUT :
VIEWS ON MULTITHREADING :