Solved

System.getProperty("file.separator") + "Desktop" +System.getProperty("file.separator") + "001.hdr";

Posted on 2004-10-04
6
840 Views
Last Modified: 2008-02-01
Hi!

I am trying to figure out someone else’s code that was written long time ago.
I am wondering what the following line does.
++++++++++++

String fileOutPath = System.getProperty("user.home") + System.getProperty("file.separator") +
                        "Desktop" + System.getProperty("file.separator") + "001.hdr";
+++++++++++

and this is the file that contains main.
++++++++++++++
import javax.swing.plaf.metal.*;
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.io.*;

class extractHeader
{
      private static boolean runOnce = false;
      private static String startDir;

      public static void main(String[] args) throws Exception
      {

      while (true){
            String mappedDrive;

            try
            {      
                  if (args[0] != null)
                        mappedDrive = args[0];
                  else
                        mappedDrive = "D";
            }
            catch (Exception e)
            {
                  mappedDrive = "D";
            }

            UIManager.setLookAndFeel(new MetalLookAndFeel());
            JFileChooser chooser = new JFileChooser();

            if (runOnce == false)
                  startDir = mappedDrive + ":" + System.getProperty("file.separator") + "scans\\Scans_for_header_ext";

            File directory = new File(startDir);

            chooser.setCurrentDirectory(directory);
            chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
            int returnVal = chooser.showOpenDialog(null);
            if (returnVal == JFileChooser.APPROVE_OPTION)
            {
                  if (runOnce == false)
                        startDir = getStartPath(chooser.getSelectedFile().getAbsolutePath());
            
                  String fileOutPath = System.getProperty("user.home") + System.getProperty("file.separator") +
                        "Desktop" + System.getProperty("file.separator") + "001.hdr";

                  File outf = new File(getOutPath(chooser.getSelectedFile().getAbsolutePath()));

                  PrintWriter out = new PrintWriter(new FileWriter(outf));
System.out.println(outf);
System.out.println(chooser.getSelectedFile());
                  DicomFile dicom = new DicomFile(chooser.getSelectedFile());

                  Vector ElementNameVector = dicom.getElementNameVector(); // names of catagories
                  Vector ElementValueVector = dicom.getElementValueVector(); // bunch of large numbers
                  Vector ElementDataStringVector = dicom.getElementDataStringVector(); // data

                  Object[] catagories = ElementNameVector.toArray();
                  Object[] data = ElementDataStringVector.toArray();

                  String finalHeader = "(";
            
                  for (int i = 0; i < ElementNameVector.size(); i++)
                  {
                        finalHeader = finalHeader + "(" + catagories[i].toString() + " " + data[i].toString() + ") ";
                  }
            
                  out.print(finalHeader);
                  out.print(")");
                  out.close();
            
            }
            else
                  System.exit(0);

            if (runOnce == false)
                  runOnce = true;
      }
      }

      public static String getOutPath(String inPath)
      {
            String[] prePath = new String[20];
            int i = 0;
            String backslash = System.getProperty("file.separator");

            StringTokenizer st = new StringTokenizer(inPath, backslash, true);

            do
            {
                  prePath[i] = st.nextToken();
                  i++;
            }
            while (st.hasMoreTokens());


            String finalOut;
            finalOut = "";

            for (int j = 0; j < i-2; j++)
            {
                  finalOut = finalOut + prePath[j];
            }

            return finalOut + ".hdr";
      }

      public static String getStartPath(String inPath)
      {
            String[] prePath = new String[20];
            int i = 0;
            String backslash = System.getProperty("file.separator");

            StringTokenizer st = new StringTokenizer(inPath, backslash, true);

            do
            {
                  prePath[i] = st.nextToken();
                  i++;
            }
            while (st.hasMoreTokens());
            
            String finalOut;
            finalOut = "";

            for (int j = 0; j < i - 8; j++)
            {
                  finalOut = finalOut + prePath[j];
            }

            return finalOut;
      }
}
++++++++++++++

thanks in advance..
0
Comment
Question by:dkim18
  • 2
  • 2
6 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 12221046
It's just constructing the path to a file on the desktop
0
 
LVL 92

Assisted Solution

by:objects
objects earned 125 total points
ID: 12221238
> String fileOutPath = System.getProperty("user.home") + System.getProperty("file.separator") +
>                    "Desktop" + System.getProperty("file.separator") + "001.hdr";

It creates a string containing the path to a file named "001.hdr" in a folder "Desktop" in the users home directory.

eg. if the users home directory is /users/dkim18 then the value of fileOutPath will be:

/users/dkim18/Desktop/001.hdr


System.getProperty("file.separator") returns the file path seperator used by the OS being run on.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12221313
String fileOutPath = System.getProperty("user.home") + "/" + "Desktop"  + "/001.hdr";

should work just as well
0
 
LVL 92

Expert Comment

by:objects
ID: 12221405
The value is never actually used in the code, so you could just get rid of it :)
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 82
Image decoding from Camera 3 85
hibernate jars 4 26
Java: How do I open the default windows program for a given file type 3 28
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now