会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132497个问题
JAVA 全系列/第二阶段:JAVA 基础深化和提高/容器(旧) 28486楼
Python 全系列/第二十阶段:数据分析-统计分析/Python统计分析 28487楼
Python 全系列/第二阶段:Python 深入与提高/游戏开发-坦克大战 28489楼
Python 全系列/第七阶段:网页编程基础/JavaScript 28490楼
Python 全系列/第七阶段:网页编程基础/JavaScript 28491楼

package cn.itbaizhan;
//客户端
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

public class Client {

    public static void main(String[] args) throws IOException {
        Socket client=new Socket("192.168.0.103",888);
        OutputStream os=client.getOutputStream();
        InputStream is=client.getInputStream();
        os.write("aaa".getBytes());
        os.flush();
        int len=0;
        byte[] bt1=new byte[1024];
        while((len=is.read(bt1))!=-1){
            System.out.println(new String(bt1,0,len));
            if(len<bt1.length){//
                break;
            }
        }
        if(is!=null){
            is.close();
        }
        if(os!=null){
            os.close();
        }
        if(client!=null){
            client.close();
        }



    }

}
========
package cn.itbaizhan;
//服务器端
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket=new ServerSocket(888);
        Socket client=serverSocket.accept();//监听
        InputStream is=client.getInputStream();
        byte[] bt2=new byte[1024];
        int len=0;
        while ((len=is.read(bt2))!=-1){
            System.out.println(new String(bt2,0,len));
        }
        OutputStream os=client.getOutputStream();
        os.write("bbb".getBytes());
        os.flush();
        if(os!=null){
            os.close();
        }
        if(is!=null){
            is.close();
        }
        if(client!=null){
            client.close();
        }
        if(serverSocket!=null){
            serverSocket.close();
        }

    }
}

blob.png

blob.png

老师,为什么我这里服务器端能读数据,客户端读不了呢

JAVA 全系列/第二阶段:JAVA 基础深化和提高/网络编程(旧) 28492楼

1练习中问题一

老师金字塔是怎么做出的呢,我的代码是在哪一处有了问题的呢


代码

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>for循环联系打印</title>
</head>
<body>
<script>
   /* /!*打印5行5列的矩形
    * * * * *
    * * * * *
    * * * * *
    * * * * *
    * * * * *
    *!/
    for (var j=1;j<5;j++){  //外层循环控制行
        for (var i=1;i<5;i++){  //内层循环控制列
            document.write("*")
        }
        document.write("<br/>");
    }*/

    /*打印5行5列的矩形
    *
    * *
    * * *
    * * * *
    * * * * *

   for (var j=1;j<5;j++){  //外层循环控制行
       for (var i=1;i<=j;i++){  //内层循环控制列
           document.write("*")
       }
       document.write("<br/>");
   }*/
   /*打印5行5列的矩形
        *
       * *
      * * *
     * * * *
    * * * * *
    */
   var alt="";
    for (var i=1;i<=5;i++){  //控制行
        var blank=""
        for (var j=1;j<=5-i;j++){  //空白三角形
            blank+=""
        }
        var stars="";
        for (var m=1;m<=2*i-1;m++){
            stars+="*";
        }
        alt+=blank+stars+"\n";
    }
    console.log(alt);

</script>
</body>
</html>

运行图.

image.png


作业图image.png


WEB前端全系列/第二阶段:JavaScript编程模块/运算符_数据类型和流程循环语句 28496楼

"C:\Program Files\Java\jdk-11.0.7\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2020.1\lib\idea_rt.jar=52695:C:\Program Files\JetBrains\IntelliJ IDEA 2020.1\bin" -Dfile.encoding=UTF-8 -classpath C:\Users\Administrator\Desktop\java\IdeaProjects\mybatisdemo\out\production\mybatisdemo;C:\Users\Administrator\Desktop\java\jarpack\mybatisjar\asm-7.1.jar;C:\Users\Administrator\Desktop\java\jarpack\mybatisjar\cglib-3.3.0.jar;C:\Users\Administrator\Desktop\java\jarpack\mybatisjar\ognl-3.2.14.jar;C:\Users\Administrator\Desktop\java\jarpack\mybatisjar\log4j-1.2.17.jar;C:\Users\Administrator\Desktop\java\jarpack\mybatisjar\mybatis-3.5.5.jar;C:\Users\Administrator\Desktop\java\jarpack\mybatisjar\log4j-api-2.13.3.jar;C:\Users\Administrator\Desktop\java\jarpack\mybatisjar\slf4j-api-1.7.30.jar;C:\Users\Administrator\Desktop\java\jarpack\mybatisjar\log4j-core-2.13.3.jar;C:\Users\Administrator\Desktop\java\jarpack\mybatisjar\commons-logging-1.2.jar;C:\Users\Administrator\Desktop\java\jarpack\mybatisjar\javassist-3.27.0-GA.jar;C:\Users\Administrator\Desktop\java\jarpack\mybatisjar\slf4j-log4j12-1.7.30.jar;C:\Users\Administrator\Desktop\java\jarpack\mybatisjar\mysql-connector-java-5.1.48.jar com.bjsxt.text.Test
log4j:WARN No appenders could be found for logger (org.apache.ibatis.logging.LogFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in SQL Mapper Configuration
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.datasource.DataSourceException: Unknown DataSource property: userpassword
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
	at com.bjsxt.dao.impl.UsersDaoImpl.selectUsersAll(UsersDaoImpl.java:25)
	at com.bjsxt.text.Test.main(Test.java:13)
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.datasource.DataSourceException: Unknown DataSource property: userpassword
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:122)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:99)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:78)
	... 3 more
Caused by: org.apache.ibatis.datasource.DataSourceException: Unknown DataSource property: userpassword
	at org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory.setProperties(UnpooledDataSourceFactory.java:55)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.dataSourceElement(XMLConfigBuilder.java:329)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.environmentsElement(XMLConfigBuilder.java:283)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:117)
	... 5 more

Process finished with exit code 1


找了一晚上没找到原因,老师帮帮忙!


666.png


源码:src.rar


JAVA 全系列/第六阶段:项目管理与SSM框架/Mybatis 28497楼
Python 全系列/第七阶段:网页编程基础/jquery 28498楼

老师晚上好!我用老师的方法了,代码如下,但是读出来还是乱码,!老师能否帮我分析一下!

package com.bjsxt;

import java.io.*;

public class DataInputStream01 {
    public static void main(String[] args) throws IOException {
     //  write();
       read();
    }
    public static void read() throws IOException {
        //读数据的方法
        //(1)找数据源
        FileInputStream fis = new FileInputStream("D://baizhan//data.txt");
        //(2)提高读取速率
        BufferedInputStream bis = new BufferedInputStream(fis);
        //(3)处理java的基本数据类型和字符串
        DataInputStream dis = new DataInputStream(bis);
     //   DataInputStream dataInputStream = new DataInputStream(new BufferedInputStream(new FileInputStream("D:\\baizhan\\data.txt")));
        //(4)读数据--(读数据的顺醋要与写的顺序一致。)
        dis.readInt();
        dis.readDouble();
        dis.readChar();
        dis.readUTF();
        //(5)关闭
        dis.close();
    }
    public static void write() throws IOException{
        //(1)目的地
        FileOutputStream fos = new FileOutputStream("D:\\baizhan\\data.txt");
        //缓冲流提高写入速度
        BufferedOutputStream bos  =new BufferedOutputStream(fos);
        //(3)数据流,增加对java基本数据类型和String的处理
        DataOutputStream  dos  = new DataOutputStream(bos);
        //(4)写入数据
        dos.writeInt(98);
        dos.writeDouble(13.5);
        dos.writeChar('d');
        dos.writeUTF("hello world!");
        //(5)关闭流
        if (dos!=null){
            dos.close();
        }
    }
}


JAVA 全系列/第二阶段:JAVA 基础深化和提高/IO 流技术(旧) 28500楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637