Solved

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

Posted on 2004-10-04
6
834 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

757 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

21 Experts available now in Live!

Get 1:1 Help Now