• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 862
  • Last Modified:

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

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
dkim18
Asked:
dkim18
  • 2
  • 2
2 Solutions
 
CEHJCommented:
It's just constructing the path to a file on the desktop
0
 
objectsCommented:
> 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
 
CEHJCommented:
String fileOutPath = System.getProperty("user.home") + "/" + "Desktop"  + "/001.hdr";

should work just as well
0
 
objectsCommented:
The value is never actually used in the code, so you could just get rid of it :)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now