Java by API/javax.swing/ProgressMonitorInputStream
Версия от 20:43, 31 мая 2010; (обсуждение)
new ProgressMonitorInputStream(Component p, Object m, InputStream i)
<source lang="java">
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(); }
}
</source>
ProgressMonitorInputStream: available()
<source lang="java">
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]); }
}
</source>
ProgressMonitorInputStream: read(byte[] b)
<source lang="java">
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]); }
}
</source>