草庐IT

system-connections

全部标签

java - Java 的 System.out.print() 会一直缓冲到 println() 吗?

我今天无意中听到关于System.out.print()的争论。一个人声称,由于print()不包括终止\n,它写入的缓冲区最终将填满并开始丢失数据。另一个人声称他们一直在为他们所有的Java程序使用System.out.print()并且从未遇到过这个问题。第一人称对吗?如果stdout已满,System.out.print()是否可以开始阻止或丢弃数据?是否有导致此问题的代码示例? 最佳答案 当System.out.print使用的缓冲区填满时,输出将写入文件(或连接到程序标准输出流的终端或其他数据目标),导致一个空缓冲区。在不

java - 提供的 java.sql.Connection 对象为空

我正在尝试将jrxml文件导出为pdf,但出现此错误:WARNquery.JRJdbcQueryExecuter-Thesuppliedjava.sql.Connectionobjectisnull.我只得到一个空白的pdf文件..这是我导出为PDF的方法:publicvoidprintReport(ActionEventevent)throwsJRException,IOException{StringreportPath=FacesContext.getCurrentInstance().getExternalContext().getRealPath("/test.jrxml")

java - System.getProperty ("java.class.path") 和 getClassLoader.getURLs() 有什么区别?

System.getProperty("java.class.path")返回我程序的类路径。然而getClassLoader().getURLs()也为我提供了类路径(参见我的另一篇文章:howtousegetClassLoader)这两种方式有什么区别? 最佳答案 主要区别在于它们返回的内容:getClassLoader.getURLs()返回用于加载类和资源的URL的搜索路径。这包括指定给构造函数的原始URL列表,以及随后由addURL()方法附加的任何URL,请参阅linkSystem.getProperty("java.c

java - 如何将 Jdbc4Connection 转换为 PGConnection?

我想像这样使用postgresCopyManager:CopyManagercp=((PGConnection)dataSource.getConnection()).getCopyAPI();当我使用spring-boot时,数据源是org.apache.tomcat.jdbc.pool.DataSource,因此连接是Jdbc4Connection。问题:转换抛出以下错误:java.lang.ClassCastException:com.sun.proxy.$Proxy55cannotbecasttoorg.postgresql.PGConnection此外,当我尝试转换为Jdbc

java - Tomcat : HikariCP issue when deploying two applications with DB connection

我试图在同一个tomcat7实例上部署两个WAR文件(app1.war和app2.war)。我收到此错误:UnabletoregisterMBean[HikariDataSource(HikariPool-0)]withkey'dataSource';nestedexceptionisjavax.management.InstanceAlreadyExistsException:com.zaxxer.hikari:name=dataSource,type=HikariDataSource如果我在tomcat上只部署了一个应用程序,我就不会出现这个错误。有办法解决这个问题吗?

java - 使用 System.out.print 与 println 的多线程问题

我有以下线程,它每200毫秒打印一个点:publicclassProgress{privatestaticbooleanthreadCanRun=true;privatestaticThreadprogressThread=newThread(newRunnable(){publicvoidrun(){while(threadCanRun){System.out.print('.');System.out.flush();try{progressThread.sleep(200);}catch(InterruptedExceptionex){}}}});publicstaticvoid

javax.mail.MessagingException : Could not connect to SMTP host?

以下是我发送邮件的代码:importjava.util.Properties;importjavax.mail.Authenticator;importjavax.mail.Message;importjavax.mail.Message.RecipientType;importjavax.mail.MessagingException;importjavax.mail.PasswordAuthentication;importjavax.mail.Session;importjavax.mail.Transport;importjavax.mail.internet.Internet

java - 奇怪的 'out' 变量,System.out.println()

以下是java.lang.System类(JDK1.6版本)的代码publicfinalstaticPrintStreamout=nullPrintStream();//outissetto'null'privatestaticPrintStreamnullPrintStream()throwsNullPointerException{if(currentTimeMillis()>0){returnnull;}thrownewNullPointerException();}当我们在代码中编写System.out.println("Something");时,为什么即使'out'设置为'

java.net.SocketException : Network is unreachable: connect 异常

我正在尝试使用此方法从Web服务器下载xml文本文件:staticvoiddownload(Stringurl,StringfileName)throwsIOException{FileWriterxmlWriter;xmlWriter=newFileWriter(fileName);System.out.println("URLtodownloadis:"+url);//hereExceptionisthrown/////////////////////////////////BufferedReaderinputTxtReader=newBufferedReader(newBuff

java - 为什么 System.out.print() 不工作?

所以我正忙着编写一个我认为是相对简单的“读取文件”程序。我遇到了很多编译错误,所以我开始尝试一次编译一行,看看我在哪里被清理了。这是我到目前为止的位置:importjava.nio.file.*;importjava.io.*;importjava.nio.file.attribute.*;importjava.nio.channels.FileChannel;importjava.nio.ByteBuffer;importstaticjava.nio.file.StandardOpenOption.*;importjava.util.Scanner;importjava.text.*