Java I/O????????С??
???????????? ???????[ 2014/3/19 10:55:21 ] ????????Java ??????
????File??
????File???? IO ???д????????????????????File???????Щ????????????????????
????File f = new File("d:/test/1.txt");
???????÷????? API
????delete ?????????File?????·??????? ????????????????????????????????????е????????????
?????????
?????????IO???????????????????????????????д?????????
????1. ???????????????????豸?????????н??????
????2. ??????????????????????????y????????????????????д???????????????????????????????????д???????
????InputStream ?? OutputStream (??????[?????])
?????????????????? ?????? ????????????????InputStream?????
int read() // ???? -1 ????????????β??????
int read(byte[] b) //????b.length????????b?в?????????????????
int read(byte[] b??int off??int len)
void close() //?????????????????????????
???????????????????? д????? ???????????????OutputStream?????
void write(int b) //????????д????????
void write(byte[] b) //?????????????д?????????
void write(byte[] b??int off??int len) //
void flush() //????????????????????
void close() //????????
??????????????????????????????????????
???????? ?????? ?????????д??
??????A?????????д?????B?У?
?????????????????????????????A?????????????????????????????B??????????
????FileInputStream ?? FileOutputStream
???????????????????????????????????????FileInputStream??????????????????????·?????????????????????????????????????????FileOutputStream???????????????????????????
????????????????????????飡??????????????????getBytes()????????????顣
???????unicode??????????ASCII????????java?е??????????unicode????
??????????????FileOutputStream???????д??????????????FileInputStream??????
public class FileStreamDemo {
public static void main(String[] args) {
File f = new File("Hello.txt");
//??????????
try {
FileOutputStream out = new FileOutputStream(f);
byte buf[] = "hello??well".getBytes();//?????????
out.write(buf);
out.close();
} catch (Exception e) {
e.printStackTrace();
}
//??????ж?????????????
try {
FileInputStream in = new FileInputStream(f);
byte[] buff = new byte[1024];
int len = in.read(buff);
System.out.println(new String(buff??0??len));
} catch (Exception e) {
e.printStackTrace();
}
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11