InputStream and OutputStream UML:
Example Test:
public static void main(String[] args) throws IOException{
String fileName = "...";
String toFileName = "...";
java.io.InputStream inputStream = null;
java.io.OutputStream outputStream = null;
int len = 2048;
byte[] bytes = new byte[len];
try{
inputStream = new FileInputStream(fileName);
outputStream = new FileOutputStream(toFileName);
while((len = inputStream.read(bytes, 0, len)) != -1){
outputStream.write(bytes, 0, len);
}
outputStream.flush();
}catch(IOException e){
e.printStackTrace();
}finally{
try{
if(inputStream != null){
inputStream.close();
inputStream = null;
}
if(outputStream != null){
outputStream.close();
outputStream = null;
}
}catch(Exception e){
e.printStackTrace();
}
}
}
Reader and Writer UML:
Example Test:
public static void main(String[] args) throws IOException{
String fileName = "...";
String toFileName = "...";
java.io.BufferedReader bufferedReader = null;
java.io.BufferedWriter bufferedWriter = null;
String lineString = null;
try{
bufferedReader = new BufferedReader(new FileReader(fileName));
bufferedWriter = new BufferedWriter(new FileWriter(toFileName));
while((lineString = bufferedReader.readLine()) != null){
System.out.println(lineString);
bufferedWriter.write(lineString+"\n");
}
bufferedWriter.flush();
}catch(IOException e){
e.printStackTrace();
}finally{
try{
if(bufferedReader != null){
bufferedReader.close();
bufferedReader = null;
}
if(bufferedWriter != null){
bufferedWriter.close();
bufferedWriter = null;
}
}catch(IOException e){
e.printStackTrace();
}
}
}