CSS font stacks, media style sheets & web standards

Your banner ad here

WestNIC provides reliable web hosting services

25% off cpanel web hosting and reseller hosting deals. Promo: codestyle25off

Site navigation below

This FAQ is part of the Code Style Help and FAQ section. Join our premium content service for full access all FAQs, or choose the single FAQ by email option for premium answers.

Read and write files

Q: How can I divert console output to a file?

A: The java.lang.System class holds a static reference to the console output stream in its System.out field, which is an instance of java.io.PrintStream. The System.setOut(PrintStream) method allows you to assign a different output to the reference. In this case you can construct a PrintStream from a FileOutputStream, as below.

premium content omitted

Premium Content: Follow this link for subscription information Get full access to all FAQs, subscribe now for $40
How can I divert console output to a file?

Get the answer to this FAQ by email Get the full answer to this FAQ by email for $2.99
within 24 hours of clearance by PayPal.

Actions: Follow-up, clarify or correct this answer. Submit a new question.

Q: How can I generate an array from a list?

A: The answer to your question would depend on the format of the list, which is perhaps stored in a file? If there is a consistent character pattern that separates the list items, you might use a StringTokenizer to capture them. Create a BufferedReader from a FileReader and use the readLine() method to acquire the data.

premium content omitted

Premium Content: Follow this link for subscription information Get full access to all FAQs, subscribe now for $40
How can I generate an array from a list?

Get the answer to this FAQ by email Get the full answer to this FAQ by email for $2.99
within 24 hours of clearance by PayPal.

Actions: Follow-up, clarify or correct this answer. Submit a new question.

File system navigation

Q: How can I get the full path of Explorer.exe?

A: Firstly, you cannot generally obtain this reference from an applet loaded via the Internet because the Java sandbox will not permit this type of system access.

premium content omitted

Premium Content: Follow this link for subscription information Get full access to all FAQs, subscribe now for $40
How can I get the full path of Explorer.exe?

Get the answer to this FAQ by email Get the full answer to this FAQ by email for $2.99
within 24 hours of clearance by PayPal.

Actions: Follow-up, clarify or correct this answer. Submit a new question.

Q: How can I get the path to an installed program?

A: You can check for programs added to the host system's path environment variable through the java.lang.System class' getenv() method, or getenv(String), provided the application has the necessary security permission. The getenv() method returns a map of all environment variables in the current user session, getenv(String) returns the String value of the variable named by the argument, if it exists.

premium content omitted

Premium Content: Follow this link for subscription information Get full access to all FAQs, subscribe now for $40
How can I get the path to an installed program?

Get the answer to this FAQ by email Get the full answer to this FAQ by email for $2.99
within 24 hours of clearance by PayPal.

Actions: Follow-up, clarify or correct this answer. Submit a new question.

Q: How do I limit the scope of a file chooser?

A: The general mechanism for limiting file selection is to use a FileFilter. You could write a custom filter that only accepts files in a specified directory for instance. This would not stop users from browsing the file system, but would ensure that no other files could be selected.

premium content omitted

Premium Content: Follow this link for subscription information Get full access to all FAQs, subscribe now for $40
How do I limit the scope of a file chooser?

Get the answer to this FAQ by email Get the full answer to this FAQ by email for $2.99
within 24 hours of clearance by PayPal.

Actions: Follow-up, clarify or correct this answer. Submit a new question.

Q: Is it possible to convert a string to an abstract path?

A: The java.io.File class has various methods for creating abstract file paths, which can then be created on the file system or used to test whether the actual file paths exist. The simple constructor File(String) takes an argument that is a complete abstract path name. In the File(File, String) constructor, the File argument is a parent directory reference and the String is a path name under that directory. See the JDK API documentation for further details about listing, creating, testing, comparing, deleting and setting the properties of files.

Actions: Follow-up, clarify or correct this answer. Submit a new question.

Input and output streams

Q: Why are streams used in Java?

A: In Java streams are used to process input and output data as a sequence of bytes, which does not assume a specific character content or encoding. Byte content can be read from network sources, files and other sources, and bytes copied between multiple inputs and outputs.

Streams types can be sub-classed to add filtering, to mark a point in the stream and re-read those bytes, or to skip a number of bytes. Streams also enable serlializable objects to stored and re-constructed using ObjectInputStream and ObjectOutputStream types.

Actions: Follow-up, clarify or correct this answer. Submit a new question.

Q: What does "broken pipe" mean?

A: A pipe is an input/output link between two programs, commonly where you use the output from one program as the input for another program. A broken pipe means that the linkage between the output and input is interrupted, the reasons vary. For example, the feeder program may throw an error and terminate unexpectedly, intermediate source or output files may not be created successfully, or key resources become unavailable during the process. You may also get problems with the amount of swap file storage or overall memory usage approaches its limits.

Actions: Follow-up, clarify or correct this answer. Submit a new question.

Add this page to your chosen social bookmarking service

Style warning - please read

Home · CSS · Java · Javascript · HTML · Help · Log