JAVA基础(二)

1、java中的继承只可以继承一个父类,可以通过实现接口的方法来弥补这一缺点。但是实现一个借口就必须需要实现接口里面的方法,接口中方法不能有方法体,同时方法的访问修饰符不能是 private 和 protected。

2、抽象类中的方法一定要用abstract来修饰

3、对于使用Calendar来获取到的时间,其中Calendar.month中0代表的是一月份,所以如果需要得到正常的数值,则需要加一。

4、不要直接在class中写代码,应该在方法中补全自己的代码。

5.对于java中的文件操作,如果不想一次读取一行,那么应该怎么操作呢,可以一次全部把所需要的数据全部读出,保存到一个byte数组中,然后使用String的构造方法把数组转换成一个字符串。实例如下:

package read;

/**
 * Created with IntelliJ IDEA.
 * User: shuaiy
 * Date: 16-9-25
 * Time: 下午83:28
 * To change this template use File | Settings | File Templates.
 */
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class ReadFile {
    public static void main(String args[]) throws IOException {
        File file = new File("E:\\json\\readFile\\src\\read", "12.txt");
        Long filelength = file.length();
        byte[] content = new byte[filelength.intValue()];
        FileInputStream in = null;
        try {
            in = new FileInputStream(file);
        } catch (FileNotFoundException e1) {
            e1.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        try {
            in.read(content);
            in.close();
        } catch (IOException e1) {
            e1.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }

         System.out.println(new String(content));
    }
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值