Solved

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

Posted on 2004-10-04
6
849 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

687 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