新行“ "的重要性在 Java 网络中 [英] Importance of the new line " " in Java networking

查看:21
本文介绍了新行“ "的重要性在 Java 网络中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我需要澄清一下这里的 String 变量中 "新行的重要性

Well, I need a clarify of what is the importance of the " " new line in the String variable here

import java.net.*;
import java.io.*;

public class Whois{
    public static void main(String[] args){
        try{
            Socket soc = new Socket("whois.internic.net",43);
            InputStream in = soc.getInputStream();
            OutputStream out = soc.getOutputStream();
            String url = "http://www.infiniteskills.com
";
            byte[] buffer = url.getBytes();
            out.write(buffer);
            int c;
            while((c = in.read()) != -1){
                    System.out.print((char)c);  
            }
            in.close();
            out.close();
        }catch(IOException e){
            System.out.println(e.getMessage());
        }
    }
}

注意:- 如果没有 ,程序将无法正常工作且无输出.

Note :- without the the program doesn't work correctly and no output.

推荐答案

换行符在 Java 网络中并不重要.

The newline has no importance in Java networking.

然而,它在许多协议中确实很重要,其中许多基于 作为行终止符的Telnet 终端"约定.这当然包括 SMTP、FTP、HTTP 和 Telnet 本身.

However it does have importance in many protocols, many of which are based on the 'Telnet Terminal' convention of as the line terminator. This certainly includes SMTP, FTP, HTTP, and Telnet itself.

它对于 BufferedReader.readLine() 方法也很重要.你会在这里找到数百个关于 readLine() 永远阻塞的问题,答案是你正在阅读行但你没有写行",即只是发送一个没有行终止符的字符串.这并不构成完整的一行,因此 readLine() 不会返回它.

It also has importance for the BufferedReader.readLine() method. You will find hundreds of questions here about readLine() blocking forever, to which the answer is 'you are reading lines but you are not writing lines', i.e. just sending a string with no line terminator. This does not constitute a complete line, so readLine() doesn't return it.

这篇关于新行“ "的重要性在 Java 网络中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆