입출력을 대충 공부하고 복붙으로만 쓰다가 제대로 실습!
InputStreamis = null;
OutputStreamos = null;
try {
is = newFileInputStream("/Users/ryanhan/test.txt");
os = newFileOutputStream("/Users/ryanhan/test2.txt");
while(true) {
inti = is.read();
if(i==-1)
break;
os.write(i);
}
} catch (Exceptione) {
e.printStackTrace();
} finally {
if(is != null) {
try {
is.close();
} catch (Exceptione2) {
e2.printStackTrace();
}
} if(os != null) {
try {
os.close();
} catch (Exceptione2) {
e2.printStackTrace();
}
}InputStreamis = null;
OutputStreamos = null;
try {
is = newFileInputStream("/Users/ryanhan/test.txt");
os = newFileOutputStream("/Users/ryanhan/test2.txt");
byte[] bs = newbyte[5];
while(true) {
intcount = is.read(bs);
if(count == -1) {
break;
}
os.write(bs, 0, count);
}
} catch (Exceptione) {
e.printStackTrace();
} finally {
if(is != null) {
try {
is.close();
} catch (Exceptione2) {
e2.printStackTrace();
}
}
if(os != null) {
try {
os.close();
} catch (Exceptione2) {
e2.printStackTrace();
}
}
}InputStreamis = null;
DataInputStreamdis = null;
OutputStreamos = null;
DataOutputStreamdos = null;
try {
is = newFileInputStream("Users/ryanhan/test.txt");
dis = newDataInputStream(is);
Stringstr = dis.readUTF();
os = newFileOutputStream("Users/ryanhan/test2.txt");
dos = newDataOutputStream(os);
dos.writeUTF(str); } catch (Exceptione) {
} finally {
if( dos != null) {
try {
dos.close();
} catch (Exceptione2) {
e2.printStackTrace();
}
}
if(os != null) {
try {
os.close();
} catch (Exceptione2) {
e2.printStackTrace();
}
}
}