老师,为什么finally里面都要加try catch?
老师 那个先运算后加减和先加减后运算具体的区别是什么呀
try { //创建字节输入流对象 fis = new FileInputStream("d:/a.txt"); int s1 = fis.read(); //打印输入字符a对应的ascii码值97 int s2 = fis.read(); //打印输入字符b对应的ascii码值98 int s3 = fis.read(); //打印输入字符c对应的ascii码值99 int s4 = fis.read(); //由于文件内容已经读取完毕,则返回-1 System.out.println(s1); System.out.println(s2); System.out.println(s3); System.out.println(s4); } catch (Exception e) { e.printStackTrace();
try{
}catch(){
}这个是什么意思?
e.printStackTrace();
这个语句是什么意思?
老师好,我想问下:
为什么这里用到的ByteArrayInputStream不需要在外面定义/不需要手动关闭?
为什么之前 new ByteArrayOutputStream不可以放在new DataOutputStream里一起定义,而这里可以放在里面定义啊,还是有点不懂
老师,不好意思,我想请问一下本节内容的图片文件在哪里下载的啊,我把这三个全部下载了,好像也没有啊
这个遍历方法的格式是什么啊,不是很懂,这是什么方法啊
为什么这里都开始用包装类的符号来定义数据类型而不能再用int,char这样的了呢
既然“?”可以作为一个占位符来用,那岂不是什么类型都能用“?”了吗那为什么还需要有其他的什么E、T、K类型的符号啊
char c=(char)reader.read();
老师这句上节课讲的也有异常 为啥这节课不放在try的括号里面也不报红
照著老師的代码敲的找不到为什么会报这个错误
package com.bjsxt; public class MySinglyLinkedList<E> implements MyList<E> { class Node<E>{ private E item; private Node next; Node(E item, Node next){ this.item =item; this.next = next; } } private Node head; private int size; @Override public void add(E element) { Node<E> node = new Node<>(element,null); Node tail = getTail(); if (tail == null){ this.head = node; }else{ tail.next = node; } this.size++; } private Node getTail(){ if(this.head == null){ return null; } Node node = this.head; while (true){ if(node.next == null)break; node = node.next; } return node; } @Override public E get(int index) { this.checkIndex(index); Node<E> node = this.getNode(index); return node.item; } private void checkIndex(int index){ if(!(index >= 0 && index < this.size)){ throw new IndexOutOfBoundsException("Index:"+index+"Size:"+this.size); } } private Node getNode(int index){ Node<E> node = this.head; for (int i=0;i<index;i++){ node = node.next; } return node; } @Override public E remove(int index) { this.checkIndex(index); Node<E> node = this.getNode(index); E item = node.item; if(this.head == node){ this.head = node.next; }else{ Node<E> temp =this.head; for(int i=0;i<index-1;i++){ temp = temp.next; } temp.next = node.next; } node.next = null; this.size--; return item; } @Override public int size() { return this.size; } public static void main(String[] args) { MySinglyLinkedList<String> mySinglyLinkedList = new MySinglyLinkedList<>(); MySinglyLinkedList.add("a"); MySinglyLinkedList.add("b"); MySinglyLinkedList.add("c"); MySinglyLinkedList.add("d"); System.out.println(MySinglyLinkedList.size()); } }
老师这两个结果都是一样的,是不是不用转型啊,String类是object 的子类
老师我i想知道 视频里面老师那个boolean flag 是怎么用快捷方法敲出来的还是手速快?
我标出来的这个是什么意思啊老师
老师这两种方法run出来的结果都一样,是说明这两种方法没有区别吗
package com.itbaizhan.li.InternetCoding; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.InetAddress; import java.net.ServerSocket; import java.net.Socket; /** * 一对多的服务器 */ class Msg extends Thread{ private Socket socket; public Msg(Socket socket){ this.socket=socket; } @Override public void run() { this.sendMsg(); } private void sendMsg(){ BufferedReader br=null; PrintWriter pw=null; try { br=new BufferedReader(new InputStreamReader(socket.getInputStream())); pw=new PrintWriter(socket.getOutputStream()); //这行有疑问 while(true){ pw.println(br.readLine()+"[ok]"); pw.flush(); } }catch (Exception e){ e.printStackTrace(); }finally { if(br!=null){ try { br.close(); } catch (IOException e) { e.printStackTrace(); } } if(pw!=null){ pw.close(); } } } } public class EchoServer { public static void main(String[] args) { ServerSocket serverSocket=null; try { serverSocket=new ServerSocket(8888); System.out.println("服务器已启动,正在监听。。。"); while(true){ Socket socket=serverSocket.accept(); new Msg(socket).start(); } }catch (Exception e){ e.printStackTrace(); }finally { if(serverSocket!=null){ try { serverSocket.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
在第31行中未加while循环导致客户端发送消息时,服务端返回了如下的结果图一的结果
我的理解是图三中的while循环死循环了,老师为什么在一对多的服务端类中加了while循环后就不会这样了呢?
图一:
图二:
图三:
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637