A few days ago, I shared a new feature of Java 18: the jwebserver command line function of a simple web server .
Another way today is to use Java code to implement a static resource server.
For the detailed steps, I recorded a video and put it on station B. Interested partners can click to view the new features of Java 18: Simple Web Server (2)
The code is relatively simple, and it is directly posted:
public class Main {
public static void main(String[] args) {
System.out.println("Hello world!");
var addr = new InetSocketAddress(9000);
var server = SimpleFileServer.createFileServer(
addr, Path.of("/"), SimpleFileServer.OutputLevel.INFO);
server.start();
}
}
Consolidate the content of the previous jwebserver. According to the above code, if you use jwebserver to implement it, it is actually the following command:
jwebserver -p 9000 -d / -o info
See if your understanding is correct!
Well, today's sharing is here! If you encounter difficulties in the learning process? You can join our high-quality technical exchange group , participate in exchanges and discussions, and learn and progress better!
Also, don't walk away, follow me! Continue to update the Java frontier column !
Welcome to my public account: Programmer DD. Learn about cutting-edge industry news for the first time, share in-depth technical dry goods, and obtain high-quality learning resources
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。