package cn.jscn.tz; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.Scanner; public class test { public static void main(String[] args) throws ParseException { System.out.println("请输入一个日期:yyyy-MM-dd"); Scanner input =new Scanner(System.in); String str=input.next(); DateFormat df=new SimpleDateFormat("yyyy-MM-dd"); Date d=df.parse(str); Calendar cal=new GregorianCalendar(); cal.setTime(d); int nowDate =cal.get(Calendar.DAY_OF_MONTH); cal.set(Calendar.DAY_OF_MONTH, 1); int dayOfWeek=cal.get(Calendar.DAY_OF_WEEK); System.out.println("日\t一\t二\t三\t四\t五\t六"); for(int i=1;i<dayOfWeek;i++) { System.out.print("\t"); } int dayMax=cal. getActualMaximum(Calendar.DAY_OF_MONTH); for(int i=1;i<=dayMax;i++) { System.out.print(i); if(i==nowDate) { System.out.print("*"); } System.out.print("\t"); if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY) { System.out.println(); } cal.add(Calendar.DAY_OF_MONTH, 1); } } }
cal.add(Calendar.DAY_OF_MONTH, 1);循环每循环一次就增加一天,这个地方没有理解,我把这行代码删除后,
不是已经有判断是星期六就换行么?为什么这个代码删除后
if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY) { System.out.println(); 就没有自动换行呢
如果books 里面有属性值,它是不是也要算一个字节点个数?(就是解析上一章课的book.xml)
package BufferedInputStream_01; import java.io.*; /* * BufferedInputStream 缓冲字节流,用于提高读取效率 * 同时也是处理流(包装流) */ public class BufferInputStream_01 { public static void main(String[] args) throws IOException{ File sourceAddress = new File(File.separator+"Users"+File.separator+"luo"+File.separator); File sourceFile = new File(sourceAddress,"Downloads"+File.separator+"pconline1572649741588.dmg"); File destniyFile = new File(sourceAddress,"Desktop"+File.separator+sourceFile.getName()); File desktopDirectory=new File(sourceAddress,"Desktop"+File.separator); byte[]buffer = new byte[10]; FileInputStream fi = new FileInputStream(sourceFile); if(fi.markSupported()) { fi.mark(fi.available()); }else { System.out.println("不支持标记"); } FileOutputStream fo= new FileOutputStream(destniyFile); long currentTime = System.currentTimeMillis(); int times=0; int length=0; while((length=fi.read(buffer))!=-1) { times++; fo.write(buffer,0,length); } fo.flush(); long finishTime = System.currentTimeMillis(); System.out.println("中转"+times+"次\t使用字节流总共耗时"+(finishTime-currentTime)+"毫秒"); //fi.reset(); fi.close(); fi = new FileInputStream(sourceFile); Reader reader = new InputStreamReader(fi); FileOutputStream tempForWriter=new FileOutputStream(new File(desktopDirectory,"(1).dmg")); Writer writer = new OutputStreamWriter(tempForWriter); times=0; length=0; char[] bufferC = new char[buffer.length]; long readerTime = System.currentTimeMillis(); while((length=reader.read(bufferC))!=-1) { times++; writer.write(bufferC,0,length); /*也许用字符来复制就是打不开*/ } tempForWriter.flush(); writer.flush(); long writerTime = System.currentTimeMillis(); System.out.println("中转"+times+"次\t使用字符流总共耗时"+(writerTime-readerTime)+"毫秒"); times=0; length=0; byte[] buffer3 = new byte[buffer.length]; long bufferedTime = System.currentTimeMillis(); //fi.reset();不支持流标记 fi.close(); fi = new FileInputStream(sourceFile); BufferedInputStream bi = new BufferedInputStream(fi); FileOutputStream tempForBuffered = new FileOutputStream(new File(desktopDirectory,"(2).dmg")); BufferedOutputStream bo = new BufferedOutputStream(tempForBuffered); while((length=bi.read(buffer3))!=-1) { times++; bo.write(buffer3,0,length); /*不加长度,复制出来的文件一定打不开*/ } bo.flush(); tempForBuffered.flush(); long bufferedFinish = System.currentTimeMillis(); System.out.println("使用buffered总共读取了"+times+"次" +"\t耗时"+(bufferedFinish-bufferedTime)+"毫秒"); writer.close(); reader.close(); tempForWriter.close(); bo.close(); bi.close(); tempForBuffered.close(); fi.close(); fo.close(); System.out.println("拷贝完成"); } }
老师您好,我的是Mac系统,为什么字节流和缓冲字节流,复制应用程序后能打开,但是字符流就是打不开,我找不到错误的地方
问题:
老师能讲解下字符流和字节流俩者之间使用的区别别吗,在应用当中。视频内使用方法基本类似,但不清楚实际运用的选择。
老师:
视频中地文档第三条,减少冲突,装填因子是0.5;这句话怎么理解呢??
如果数组中元素相同,就不再添加,那会不会出现元素个数缺是的情况,如果不会的话,那是怎么标记重复的元素的呢?
按照视频中老师的讲述来看的话。linkedList 的第一个节点元素的前驱指针域是first,不应该是指向他本身的数据域的么?怎么会是空的呢?
HashMap 与 Hashtable 的区别
JDK引入版本
这节的源码怎么保存啊?
Vector用法和ArrayList区别总结如下:
在执行客户端的时候,出现了下面的异常
老师这个异常该怎么解决?
请问:如果要使用 ListIterator 迭代器进行反向遍历,是否必须要先进行一次正向迭代后才行?
请问老师,在方法定义中,我们可以看到有时会有 E, T 这样的类型参数,请问这代表什么?
有以下几个问题想请教一下:
① String类型的常量,在常量池中是字节形式的的吧,比如“abc”,其实就是['a','b','c'] 的数组?
② 那如果是这样的话一个字符占用的空间是一个字节;那么如果出现中文呢,比如"你abc好hello",这样的,在底层是怎么存储的呢?
我在用javac命令时,报错这个,时因为我的文档的编码格式不对么?编码格式不对,运行不是应该出现乱码么,怎么直接编译都不通过呢?
代码:
public class Test { public static void main(String[] args) { String str1 = "abc" + "dbc"; String str4 = "abcdbc"; String str2 = str1 + "cde"; String str3 = new String("hello"); System.out.println(str1 == str4); /** 等号右侧有变量参与运算或者有new关键字时,将会在对内存中开辟空间 */ } }
结果:
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637