一开始我指定的路径是相对路径,就是项目下的路径
如:http://127.0.0.1:8888/blog/web/index.html
这段代码就是将blog/web/index.html截取出来赋值给htmlPath ,然后服务器去找这个地址时却找不到,原因: 相对路径服务器无法找到,需要在前面加上你项目在你计算机上的路径,也就是文件的绝对路径
//把inputStream网络字节输入流对象,转换为字符缓冲输入流
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
//把客户端请求信息的第一行读取出来GET /11 Net/web/index. html HTTP/1.1
String line = bufferedReader.readLine();
//把读取的信息进行切割,只要中间部分/11_ Net/web/index. html
String[] array = line.split(" ");
String htmlPath = array[1].substring(1);
//创建一个本地字节输入流,构造方法中绑定要读取的html路径
FileInputStream fileInputStream = new FileInputStream(htmlPath);
修改后
//把inputStream网络字节输入流对象,转换为字符缓冲输入流
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
//把客户端请求信息的第一行读取出来GET /11 Net/web/index. html HTTP/1.1
String line = bufferedReader.readLine();
//把读取的信息进行切割,只要中间部分/11_ Net/web/index. html
String[] array = line.split(" ");
String urlPath = "C:\\Users\\maoxiaohao\\IdeaProjects\\";
String htmlPath = array[1].substring(1);
//创建一个本地字节输入流,构造方法中绑定要读取的html路径
FileInputStream fileInputStream = new FileInputStream(urlPath+htmlPath);
```