[英]How can I get my text to not print one character per line?
I have this code which pulls the source code from the website listed.我有这个代码,它从列出的网站中提取源代码。 When the text is printed out each letter is in a different line.
当文本打印出来时,每个字母都在不同的行中。 I need the line setup to be the same as the source code on chrome.
我需要线路设置与 chrome 上的源代码相同。 How could I get it to print out like that?
我怎么能把它打印出来?
package downloader;
import java.io.*;
import java.util.*;
import java.net.*;
public class Scannerup {
public static void main(String args[]) throws IOException
{
URL obj = new URL("https://www.papajohns.com/");
URLConnection con = obj.openConnection();
InputStream in1 = con.getInputStream();
int i;
do {
i = in1.read();
if(i!=-1)
{
System.out.println((char)i);
}
}
while(i!=-1);
}
}
Notice this注意这个
if(i!=-1)
{
System.out.println((char)i); ----------> You are using println
}
Change it to将其更改为
if(i!=-1)
{
System.out.print((char)i);
}
print() - will print the required output on the same line again and again. print() - 将一次又一次地在同一行上打印所需的输出。 (This is what you should of used)
(这是你应该使用的)
println() - will print the output in the next line(This is what you use in your code) println() - 将在下一行打印输出(这是您在代码中使用的内容)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.