This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes General Computing and the fly likes Read the Windows Registry from java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "Read the Windows Registry from java" Watch "Read the Windows Registry from java" New topic

Read the Windows Registry from java

Miguel Enriquez
Ranch Hand

Joined: Mar 13, 2004
Posts: 95
hi all how Read the Windows Registry from java... basically i need know where are the Favorites folder... i try:

1) readed:
2) System.getProperty("user.home") + "/favorites" but what happend if the windows are in spanish?? a different folder...

i found the exact directory in:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Favorites

but how read the registry???

Miguel Enriquez
Ranch Hand

Joined: Mar 13, 2004
Posts: 95
Solved!!! i have the version:

C:\programa\java\Mysql>java -version
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode)



public class RegQuery {

private static final String REGQUERY_UTIL = "reg query ";
private static final String REGSTR_TOKEN = "REG_SZ";
"\"HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\" /v Favorites";

public static String getCurrentPCFavorites()
try {
Process process = Runtime.getRuntime().exec(COMPUTER_WINDOWS_FAVORITES_FOLDER);
StreamReader reader = new StreamReader(process.getInputStream());
String result = reader.getResult();
int p = result.indexOf(REGSTR_TOKEN);
if (p == -1)
return null;
return result.substring(p + REGSTR_TOKEN.length()).trim();
catch (Exception e) {
return null;

static class StreamReader extends Thread {
private InputStream is;
private StringWriter sw;

StreamReader(InputStream is) { = is;
sw = new StringWriter();

public void run() {
try {
int c;
while ((c = != -1)
catch (IOException e) { ; }

String getResult() {
return sw.toString();

public static void main(String s[]) {
System.out.println("Personal directory : " + getCurrentUserPersonalFolderPath());
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15101

Thanks for posting your solution, that will make it easier for people who have the same question to find the answer with the search function of the forum.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Michael Ernest
High Plains Drifter

Joined: Oct 25, 2000
Posts: 7292

Moving to General Computing.

Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
looks now better
Mark Spencer

Joined: Feb 02, 2008
Posts: 8
I am using the above code to get clearcase views -
HKEY_CURRENT_USER\Software\Atria\ClearCase\CurrentVersion\ClearCase Explorer\ViewsPage

but it is returning null.

Whats is the problem I don't know.

I was able to print
which is printing correctly.

The code I am using is -

I want to display contents of ViewsPage

Thanks in advance.
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 439
You are not telling what value you want like


Maki Jav

Help gets you when you need it!
charles jones

Joined: Apr 25, 2011
Posts: 2
related topic in, maybe useful
Amit Ghorpade

Joined: Jun 06, 2007
Posts: 2851

drashti Bhuta,
Your post was moved to a new topic.
start topic with new thread

|Asking Good Questions|
I agree. Here's the link:
subject: Read the Windows Registry from java
It's not a secret anymore!