最近总用Java读取文件,发现了一种我个人觉得比较好的方法,现在分享给大家
public static void main(String[] args) throws Exception
{
FileInputStream f = new FileInputStream("文件路径");
InputStreamReader fileInputStream = new InputStreamReader(f);
BufferedReader br = new BufferedReader(fileInputStream);
String str="";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
while((str=br.readLine())!=null){
Date date = sdf.parse(str); //将字符串转化成日期类型
String beDate= sdf.format(new Date(date.getTime() - 7 * 24 * 60 * 60 * 1000)); //算出七天前的日期
System.out.println(beDate);
}
}