Java by API/javax.swing/ProgressMonitorInputStream — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
Admin (обсуждение | вклад) м (1 версия) |
(нет различий)
|
Текущая версия на 14:18, 31 мая 2010
new ProgressMonitorInputStream(Component p, Object m, InputStream i)
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import javax.swing.JLabel;
import javax.swing.ProgressMonitorInputStream;
public class MainClass {
public static void main(String[] a) throws Exception {
String fileName = "BigFile.txt";
FileInputStream fis = new FileInputStream(fileName);
JLabel filenameLabel = new JLabel(fileName, JLabel.RIGHT);
Object message[] = { "Reading:", filenameLabel };
ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(null, message, fis);
InputStreamReader isr = new InputStreamReader(pmis);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
br.close();
}
}
ProgressMonitorInputStream: available()
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.JOptionPane;
import javax.swing.ProgressMonitorInputStream;
public class MainClass {
public MainClass(String filename) {
ProgressMonitorInputStream monitor;
try {
monitor = new ProgressMonitorInputStream(null, "Loading " + filename, new FileInputStream(
filename));
while (monitor.available() > 0) {
byte[] data = new byte[38];
monitor.read(data);
System.out.write(data);
}
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(null, "Unable to find file: " + filename, "Error",
JOptionPane.ERROR_MESSAGE);
} catch (IOException e) {
;
}
}
public static void main(String args[]) {
new MainClass(args[0]);
}
}
ProgressMonitorInputStream: read(byte[] b)
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.swing.JOptionPane;
import javax.swing.ProgressMonitorInputStream;
public class MainClass {
public MainClass(String filename) {
ProgressMonitorInputStream monitor;
try {
monitor = new ProgressMonitorInputStream(null, "Loading " + filename, new FileInputStream(
filename));
while (monitor.available() > 0) {
byte[] data = new byte[38];
monitor.read(data);
System.out.write(data);
}
} catch (FileNotFoundException e) {
JOptionPane.showMessageDialog(null, "Unable to find file: " + filename, "Error",
JOptionPane.ERROR_MESSAGE);
} catch (IOException e) {
;
}
}
public static void main(String args[]) {
new MainClass(args[0]);
}
}