前言
 
本期任务:毕向东老师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 FileWriterDemo {
    public static void main(String
[] args
) throws Exception
{
        
        
        
        FileWriter fw 
= new FileWriter("demo.txt");
        
        fw
.write("fsgd");
        
        
        
        
        
        fw
.close();
    }
}
 
import java
.io
.*
;
public class FileWriterDemo2 {
    public static void main(String
[] args
) {
        FileWriter fw 
= null
;
        try {
            fw 
= new FileWriter("demo.txt");
            fw
.write("dfalkjf;");
        } catch (IOException e
) {
            System
.out
.println("catch: " + e
.toString());
        } finally {
            try {
                if (fw 
!= null
)
                    fw
.close();
            } catch (IOException e
) {
                System
.out
.println(e
.toString());
            }
        }
    }
}
 
import java
.io
.*
;
public class FileWriterDemo3 {
    public static void main(String
[] args
) throws IOException 
{
        
        FileWriter fw 
= new FileWriter("demo.txt", true);
        fw
.write("\r\n这是续写的部分内容。。。。\r\n");
        fw
.close();
    }
}
 
import java
.io
.FileReader
;
import java
.io
.IOException
;
public class FileReaderDemo {
    public static void main(String
[] args
)throws IOException 
{
        
        
        FileReader fr 
= new FileReader("demo.txt");
        
        
        int ch 
= 0;
        while ((ch
=fr
.read())!=-1){
            System
.out
.println((char)ch
);
        }
        fr
.close();
    }
}
 
import java
.io
.FileReader
;
import java
.io
.IOException
;
public class FileReaderDemo2 {
    public static void main(String
[] args
) throws IOException 
{
        FileReader fr 
= new FileReader("demo.txt");
        
        
        char[] buf 
= new char[1024];
        int num 
= 0;
        while ((num 
= fr
.read(buf
)) != -1) {
            System
.out
.println(new String(buf
, 0, num
));
        }
        fr
.close();
    }
}
 
import java
.io
.*
;
public class CopyText {
    public static void main(String
[] args
) throws Exception
{
        FileReader fr 
= new FileReader("demo.txt");
        FileWriter fw 
= new FileWriter("demo_copy.txt");
        char[] buf 
= new char[1024];
        int num 
= 0;
        while ((num
=fr
.read(buf
))!=-1){
            fw
.write(buf
, 0, num
);
        }
        fr
.close();
        fw
.close();
    }
}
 
import java
.util
.*
;
import java
.text
.*
;
public class DateDemo {
    public static void main(String
[] args
) {
        Date d 
= new Date();
        System
.out
.println(d
);
        
        SimpleDateFormat sdf 
= new SimpleDateFormat("yyyy年MM月dd日 E kk:mm:ss");
        System
.out
.println("time: "+sdf
.format(d
));
        long l 
= System
.currentTimeMillis();
        System
.out
.println(new Date(l
));
    }
}
 
import java
.util
.*
;
import java
.text
.*
;
public class CalendarDemo {
    public static void main(String
[] args
) {
        Calendar c 
= Calendar
.getInstance();
        System
.out
.println(c
);
        String
[] mons 
= {"1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"};
        String
[] weeks 
= {"星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"};
        int year 
= c
.get(Calendar
.YEAR
);
        int month 
= c
.get(Calendar
.MONTH
);
        int day 
= c
.get(Calendar
.DAY_OF_MONTH
);
        int week 
= c
.get(Calendar
.DAY_OF_WEEK
);
        System
.out
.println(year 
+ "年" + mons
[month
] + day 
+ "日" + weeks
[week
]);
    }
}
 
import java
.util
.*
;
public class CalendarDemo2 {
    public static void main(String
[] args
) {
        curTimeYesterday();
    }
    public static int howManyDaysInFebruary(int year
) {
        Calendar c 
= Calendar
.getInstance();
        c
.set(year
, 2, 1);
        c
.add(Calendar
.DAY_OF_MONTH
, -1);
        return c
.get(Calendar
.DAY_OF_MONTH
);
    }
    public static void curTimeYesterday() {
        Calendar c 
= Calendar
.getInstance();
        c
.add(Calendar
.DAY_OF_MONTH
, -1);
        int year 
= c
.get(Calendar
.YEAR
);
        int month 
= c
.get(Calendar
.MONTH
)+1;
        int day 
= c
.get(Calendar
.DAY_OF_MONTH
);
        int hour 
= c
.get(Calendar
.HOUR
);
        int min 
= c
.get(Calendar
.MINUTE
);
        int sec 
= c
.get(Calendar
.SECOND
);
        System
.out
.println("昨天的这个时候是:" + year 
+ "年" + month 
+ "月" + day 
+ "日" + hour 
+ "时" + min 
+ "分" + sec 
+ "秒");
    }
}
 
import java
.util
.*
;
public class MathDemo {
    public static void main(String
[] args
) {
        saveTwo(12.3456, 2, true); 
    }
    public static void saveTwo(double d
, int scale
, boolean isRound
) {
        double base 
= Math
.pow(10, scale
);
        double num 
= isRound 
? Math
.round(d 
* base
) / base 
: (int) (d 
* base
) / base
;
        System
.out
.println("num = " + num
);
    }
    public static void show() {
        
        System
.out
.println(Math
.ceil(16.34)); 
        System
.out
.println(Math
.floor(12.34));
        System
.out
.println(Math
.round(12.34));
        System
.out
.println(Math
.pow(2, 3));
        System
.out
.println("..................................");
        
        Random r 
= new Random();
        for (int x 
= 0; x 
< 10; x
++) {
            System
.out
.println(r
.nextInt(10) + 1);
        }
    }
}
 
import java
.util
.*
;
public class SystemDemo {
    public static void main(String
[] args
) {
        Properties prop 
= System
.getProperties();
        
        for (Object obj
: prop
.keySet()){
            System
.out
.println(obj
+"::"+prop
.get(obj
));
        }
        
        System
.setProperty("myKey", "myValue");
        
        System
.out
.println("os.name: "+ System
.getProperty("os.name"));
        System
.out
.println("myKey: "+ System
.getProperty("myKey"));
    }
}
 
public class RuntimeDemo {
    public static void main(String
[] args
) throws Exception 
{
        Runtime r 
= Runtime
.getRuntime();
        Process p 
= r
.exec("notepad.exe RuntimeDemo.java");
        Thread
.sleep(4000);
        p
.destroy();
    }
}