What ist most concise way to read the contents of a file or input stream in Java? Do I always have to create a buffer, read (at most) line by line and so on or is there a more concise way? I wish I could do just
String content = new File("test.txt").readFully();
...
Hello,
I'm currently looking for a possibility in Java to identify a font as symbolic like OpenOffice does.
Characters with the font Windings or Webdings and so on should be rendered with the correct "pictures".
Anyone an idea how to distinguish between normal fonts and fonts with symbols?
...
I am about to write junit tests for a XML parsing Java class that outputs directly to an OutputStream. For example xmlWriter.writeString("foo"); would produce something like <aTag>foo</aTag> to be written to the outputstream held inside the XmlWriter instance. The question is how to test this behaviour. One solution would of course be to...
Hi,
I've got a JDialog which contains a series of JPanels in a CardLayout. Some of these panels contain JTables which I would like to be resized in line with any resizing of the JDialog. I am not sure how to achieve this and any help would be greatly appreciated.
At present the tables simply remain their current size and do not scale...
I'm using Eclipse for Java development. All my sources compile fine and the resulting application compiles fine. However, I keep getting an "red-x" error notification in the Package Explorer, like this:
All my sources in this source directory (too long for the snapshot) compile fine, none of the show the "red-x" error icon.
Any sugge...
I'm relatively new to Threading in Java and I've noticed that everytime I use Thread.sleep() I have to catch InterrupetdException.
What kind of behaviour causes this, and in simple applications where I have a monitor thread can I just Ignore the exception?
...
What is the best practice to solve a Java VM crash if the follow conditions are true:
No own or third party native code. 100% pure java
The same program run on many other system without any problems.
PS: With VM crash I means that the VM write a dump file like hs_err_pid1234.log and terminate.
...
How can I use Business Interface pattern with an EJB (session bean) with Local as well remote interfaces?
...
What regex pattern would need to pass to the java.lang.String.split() method to split a string with all whitespace characters (' ', '\t', '\n', etc.) as delimiters?
...
I'm developing a Java application using Eclipse. My project has two source directories that are both built and then some files are copied into the output folder. From the output directory I then run my application and all works well.
However, I keep having these warnings:
Anyone know how to get rid of these warnings? Maybe by excludi...
I just realized from an article in CACM that Doxygen works with Java (and several other languages) too. But Java has already the Javadoc tool. Can someone explain what are the pros and cons of either approach? Are they mutually exclusive? Is there a Maven plugin for Doxygen?
...
Hello,
In eclipse developing a java app, there are several class files that are generated by a custom ant script. This happens automatically, and it is set up as an export/publish dependency for /WEB-INF/classes.
With publishing it happens alright, however on exporting to .WAR these files just got missing.
Is there a way to automate t...
In regular Java, you can get the text of a stack trace by passing a PrintWriter to printStackTrace. I have a feeling I know the answer to this (i.e. "No") but...
Is there any way to obtain the text of a stack trace in JavaME as a String?
Update:
I should mention that I'm restricted to CLDC 1.0
...
In the spirit of Best Practices: Always return a ____, never a ____, I face a similar question in my upcoming migration from JDK1.4.2 to JDK5 and more. (Yes, I know, JDK1.4.2 is EOL! ;-) ).
For functions returning a collection (which are not simple property collections), I always prefer (in JDK1.4.2) returning an Array instead of a gene...
Can Thread.getContextClassLoader() be null ? The javadoc is not really clear.
Should a library take this case into account ?
Update: the reason I asked is that beansbinding.dev.java.net dus not work in this case (and my code does setContextClassLoader(null)
...
I want to add the ability to submit, moderate and display comments on an existing set of websites. Surely there's already a bunch of open source components that can handle the following:
Comment submission
Markup validation
Private comment moderation
Threaded comment display
Locally installed (so works seamlessly with my existing regi...
I'm trying to control the execution of a Jython script from within Java and executed through a call to PythonInterpreter.exec(). The script contains calls to classes defined in Java. I'll call these classes "commands" for the discussion here. The commands can also be run on a different machine via RMI.
Since the commands take a while t...
I'm trying to track down an issue in our system and the following code worries me. The following occurs in our doPost() method in the primary servlet (names have been changed to protect the guilty):
...
if(Single.getInstance().firstTime()){
doPreperations();
}
normalResponse();
...
The singleton 'Single' looks like this:
private ...
I am trying to use ResourceBundle#getStringArray to retrieve a String[] from a properties file. The description of this method in the documentation reads:
Gets a string array for the given key from this resource bundle or one of its parents.
However, I have attempted to store the values in the properties file as multiple individual...
I'm trying to read a single XML document from stream at a time using dom4j, process it, then proceed to the next document on the stream. Unfortunately, dom4j's SAXReader (using JAXP under the covers) keeps reading and chokes on the following document element.
Is there a way to get the SAXReader to stop reading the stream once it finds ...