前言
本期任务:毕向东老师Java视频教程学习笔记(共计25天)
原视频链接:黑马程序员_毕向东_Java基础视频教程day01:编写HelloWorld程序day02:操作符与条件选择语句day03:循环语句与函数day04:数组day07:继承、抽象类与接口day08:多态day09:异常处理day11:多线程day12:线程安全与同步机制day13:String类day14:集合(ArrayList,LinkedList,HashSet)day15:集合(TreeSet)和泛型)day16:集合(HashMap、TreeMap)day17:集合框架的工具类(Arrays、Collections)day18:IO流(字符流读写)day19:IO流(字节流、转换流读写)day20:IO流(File对象)
代码
import java
.io
.*
;
public class CopyPic {
public static void main(String
[] args
) throws IOException
{
FileInputStream fis
= new FileInputStream("picture.png");
FileOutputStream fos
= new FileOutputStream("copy_picture.png");
byte[] buf
= new byte[1024];
int len
= 0;
while ((len
= fis
.read(buf
)) != -1) {
fos
.write(buf
, 0, len
);
fos
.flush();
}
fos
.close();
}
}
import java
.io
.*
;
public class CopyTextByBuf {
public static void main(String
[] args
) throws IOException
{
FileReader fr
= new FileReader("buf.txt");
FileWriter fw
= new FileWriter("buf_copy.txt");
BufferedReader bufr
= new BufferedReader(fr
);
BufferedWriter bufw
= new BufferedWriter(fw
);
String line
= null
;
while ((line
= bufr
.readLine()) != null
) {
bufw
.write(line
);
bufw
.newLine();
bufw
.flush();
}
bufr
.close();
bufw
.close();
}
}
import java
.io
.*
;
public class CopyMp3 {
public static void main(String
[] args
) throws IOException
{
BufferedInputStream bufis
= new BufferedInputStream(new FileInputStream("夜曲.wav"));
BufferedOutputStream bufos
= new BufferedOutputStream(new FileOutputStream("copy_夜曲.wav"));
int by
= 0;
while ((by
= bufis
.read()) != -1) {
bufos
.write(by
);
}
bufis
.close();
bufos
.close();
}
}
import java
.io
.*
;
public class BufferedWriterDemo {
public static void main(String
[] args
) throws IOException
{
FileWriter fw
= new FileWriter("buf.txt");
BufferedWriter bufw
= new BufferedWriter(fw
);
for (int x
=0; x
<5; x
++){
bufw
.write("abc"+x
);
bufw
.newLine();
bufw
.flush();
}
bufw
.close();
}
}
import java
.io
.*
;
public class BufferedReaderDemo {
public static void main(String
[] args
) throws IOException
{
FileReader fr
= new FileReader("buf.txt");
BufferedReader bufr
= new BufferedReader(fr
);
String line
= null
;
while ((line
= bufr
.readLine()) != null
) {
System
.out
.println(line
);
}
bufr
.close();
}
}
import java
.io
.*
;
public class LineNumberReaderDemo {
public static void main(String
[] args
) throws IOException
{
FileReader fr
= new FileReader("buf.txt");
LineNumberReader lnr
= new LineNumberReader(fr
);
String line
= null
;
while ((line
= lnr
.readLine()) != null
) {
System
.out
.println(lnr
.getLineNumber() + "::" + line
);
}
lnr
.close();
}
}
import java
.io
.*
;
public class ReadIn {
public static void main(String
[] args
) throws IOException
{
InputStream in
= System
.in
;
StringBuilder sb
= new StringBuilder();
while (true) {
int ch
= in
.read();
if (ch
== '\r')
continue;
if (ch
== '\n') {
String s
= sb
.toString();
if ("over".equals(s
))
break;
System
.out
.println(s
.toUpperCase());
sb
.delete(0, sb
.length());
}
else{
sb
.append((char) ch
);
}
}
}
}
import java
.io
.*
;
public class TransStreamDemo {
public static void main(String
[] args
) throws IOException
{
BufferedReader bufr
= new BufferedReader(new InputStreamReader(System
.in
));
BufferedWriter bufw
= new BufferedWriter(new OutputStreamWriter(System
.out
));
String line
= null
;
while ((line
= bufr
.readLine()) != null
) {
if ("over".equals(line
))
break;
bufw
.write(line
.toUpperCase());
bufw
.newLine();
bufw
.flush();
}
bufr
.close();
}
}
class Person{
public void chiFan(){
System
.out
.println("吃饭");
}
}
class SuperPerson{
private Person p
;
SuperPerson(Person p
){
this.p
= p
;
}
public void superChiFan(){
System
.out
.println("开胃酒");
p
.chiFan();
System
.out
.println("甜点");
System
.out
.println("来一根");
}
}
public class 装饰和继承
{
public static void main(String
[] args
) {
Person p
= new Person();
p
.chiFan();
System
.out
.println("-----------------");
SuperPerson sp
= new SuperPerson(p
);
sp
.superChiFan();
}
}