Solved

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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

733 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