|
|
Исходный текст программы CopyTxtFile.java
|
Оглавление |
Назад
// ==========================================
// CopyTxtFile.java
//(C) Alexandr Frolov, 1998
// E-mail: frolov@glasnet.ru
// Web: http://www.glasnet.ru/~frolov
// ==========================================
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class CopyTxtFile
{
public static void main(String args[])
{
Frame fr = new Frame("");
FileDialog fdlg;
FileInputStream is = null;
fdlg = new FileDialog(fr, "Source file");
fdlg.show();
String szSourceFilename;
szSourceFilename = fdlg.getDirectory() +
fdlg.getFile();
fdlg = new FileDialog(fr,
"Save file as...",
FileDialog.SAVE);
fdlg.show();
String szDestFilename;
szDestFilename = fdlg.getDirectory() +
fdlg.getFile();
DataInputStream dis = null;
DataOutputStream dos = null;
try
{
dis = new DataInputStream(
new FileInputStream(szSourceFilename));
dos = new DataOutputStream(
new FileOutputStream(szDestFilename));
}
catch (IOException ex)
{
System.out.println(ex.toString());
System.exit(0);
}
while(true)
{
try
{
dos.writeChar(dis.readChar());
}
catch (EOFException ex)
{
break;
}
catch (IOException ex)
{
System.out.println(ex.toString());
break;
}
}
try
{
dis.close();
dos.close();
}
catch (IOException ex)
{
System.out.println(ex.toString());
System.exit(0);
}
System.exit(0);
}
}
|
|
|