老师:为何加了个not之后,就一个都查不出来了。
为什么我的这个代码会向上覆盖
创建的数组长度为32的时候,为什么用最右边六位数字作为偏移量?2**5=32,为什么要6
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <style> .box{ width: 0px; height: 0px; border-top: 100px solid transparent; border-bottom: 100px solid transparent; border-left: 100px solid green; border-right: 100px solid transparent; } </style> </head> <body> <div class="box"></div> </body> </html>
我这个不取反
如图所示,想问一下老师,看这位同学跟您给他的解答,产生了疑惑
头发掉了一捆
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循环后就不会这样了呢?
图一:
图二:
图三:
老师好,这个程序里面小写的file到底是什么意思。我的理解里面就是一个变量的名称,为什么在代码中进行一直使用呢(file.getName)就表示文件名,是有什么其他的意思么?(整个程序是没有错误的,正常运行的)下面是我问题的地方和我的代码
package com.io; import java.io.*; public class TestCopy { public static void main(String[]args){ /**File srcFile =new File("/Users/pain_/Downloads/world.docx"); File targetFile =new File("/Users/pain_/Desktop/world.docx"); //调用复制文件的方法 cpoyFile(srcFile,targetFile); */ File srcDir =new File("/Users/pain_/Downloads/xyyyy"); File targetDir =new File("/Users/pain_/Desktop/xyyyy"); copyDir(srcDir,targetDir); } public static void copyDir(File srcDir,File targetDir){ //判断目的地文件是否存在通过exists() if(!targetDir.exists()){ targetDir.mkdir();//如果目的地不存在,需要使用File类的mkdir()方法进行创建目录 } //list()方法是返回某个目录下的所有文件和目录的文件名,返回的是String数组 //listFiles()方法是返回某个目录下所有文件和目录的绝对路径,返回的是File数组 File[] files = srcDir.listFiles(); //加强for循环 //for (循环变量类型 循环变量名称 : 要被遍历的对象) 循环体 for(File file:files) { if (file.isFile()) { //是文件复制,目录先不管,需要复制srcDir的目录下的指定文件的具体的文件 copyFile(new File(srcDir + "/" + file.getName()), new File(targetDir + "/" + file.getName())); }else{ //继续调用该方法,使用递归实现 copyDir(new File(srcDir + "/" + file.getName()), new File(targetDir + "/" + file.getName())); } } } public static void copyFile(File srcFile, File targetFile){ //提高读取效率,从数据源 BufferedInputStream bis = null; BufferedOutputStream bos = null; try { bis = new BufferedInputStream(new FileInputStream(srcFile)); //提高读取效率,写到目的地 bos = new BufferedOutputStream(new FileOutputStream(targetFile)); //边读边写 byte [] buf =new byte[1024];//中转站 int len =0;//用于存储读到的字节的个数 while((len=bis.read(buf))!=-1){ bos.write(buf,0,len); } } catch (IOException e) { e.printStackTrace(); }finally { //关闭 if(bos!=null) { try { bos.close(); } catch (IOException e) { e.printStackTrace(); } }if(bis!=null){ try { bis.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
老师,我的可以运行,不过如果导入的txt文件中的内容是中文则打印会出现看不懂的字符,我百度了还是没搞好,不懂什么原因。
老师,我想问一下我理解的对不对:就按视频里面讲的,如果在代码里开始四个线程,而且他们执行的是一个不能再线程规定执行时间执行完的任务,那么这四个线程拿着count=0的值,四个在同一优先级下抢夺全局锁,在一番抢夺全局锁和执行真实操作系统里面线程(即执行count+=1任务)之后,有一个线程率先执行完for循环内容,然后把值返回来,由于这个count是全局变量,四个线程值都同步了,然后其他三个线程前边执行的count+=1就全都没有积累下来,然后继续所以会导致最终执行结果比正确结果要小;
然后那个在视频中出现过一次执行结果正确的情况是因为可能当时cpu很快,在它们抢到锁以后,所有线程都在规定时间完成了任务,所以结果是对的,可以这么理解吗?
问题描述:
使用如下代码,i是5,5>2应该是true吧,但是浏览器没有输出if里面的内容:
结果只输出了两个<hr>的线,没有内容:
我百度了一下,网上是这样写的:
这样输出就是正常的:
请问老师这两种方法为什么第一种无法成功?
如果 i 是一个变量,假设i为一个每次都不同的随机数,比如:int i = new Random().nextInt(10) 这样的给i赋值,在这种情况下要实现上图if的功能代码应该怎么写?
//更新departments表中department_id为3的数据,将部门换成教学部,将location_id 换成6 public void updateDepartments(String department_name,int location_id,int department_id){ Connection conn=null; Statement state=null; try{ Class.forName("com.mysql.cj.jdbc.Driver"); conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/bjsxt?useUnicode=true&characterEncoding=utf-8&serverTimezone=GMT","root","mysql"); state=conn.createStatement(); String sql="update departments d set d.department_name='"+department_name+"',d.location_id="+location_id+"where d.department_id="+department_id; int flag=state.executeUpdate(sql); System.out.println(flag); }catch (Exception e){ e.printStackTrace(); }finally { if(state!=null){ try { state.close(); } catch (SQLException throwables) { throwables.printStackTrace(); } } if(conn!=null){ try { conn.close(); } catch (SQLException throwables) { throwables.printStackTrace(); } } } } public static void main(String[] args) { jdbcTest test=new jdbcTest(); //test.insertDepartments("研发部",8); test.updateDepartments("教学部",6,3); } }
老师您好,在更新数据库这节,拼接的更新语句的字符串检查了几遍,没有找到问题,报错
既然都是IOException的子类,为什么throws之后还要用try语句呢
不用好像也是没有问题的吧
import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Test01 { public static void main(String[] args) throws IOException { FileReader reader = new FileReader("D:/..."); char c = (char)reader.read(); System.out.println(c); //关闭资源 reader.close(); } }
老师怎么ping通,老师怎么ping通,
老师讲课的是在linux虚拟机下下载的?
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637