Solved

Java: file (path) naming conventions

Posted on 2006-06-29
7
569 Views
Last Modified: 2013-11-24
Currently, we are developing XSLT + Java servlets.
One question is on how to address a file (platform independent)?
What we tried (within XSL) is to address a file like that: file://///nameOfServer/.../... (with 5 slashes at the beginning).
That worked for MSIE and Firefox.

Now we address a file with the same naming convention as above and it will not work (dir.list(); = NULL).
Is there a naming convention that works on any platform (at least windows); file:///c:/temp doesn't work... And we tried many ;-)
0
Comment
Question by:go4java
  • 4
  • 3
7 Comments
 
LVL 92

Expert Comment

by:objects
ID: 17013854
file:// is a URL, so you cannot use it to create a File instance.
If you need a File then use a regular path, if you need a URL use what you cuurently using
File also has a method toURL() to convert File name to URL

> file:///c:/temp doesn't work...

try:

file:///c|/temp doesn't work...
0
 

Author Comment

by:go4java
ID: 17016179
We need a conversion rule from URL (file://///server/.../pdf/ => directory) to file naming, e.g. g:/.../pdf.
???
0
 
LVL 92

Expert Comment

by:objects
ID: 17016507
where is the url coming from?
and what do you need to do with the file?
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

Author Comment

by:go4java
ID: 17016545
Well, actually the URL is a pre-defined path to all our web resources (htm, pdf...) and is been used within XSLT engine (to produce MSIE and Firefox compatible HTM pages).
We will run a batch process (Java + XSLT) to produce some 100 web pages (based on XML imput) and need to search files on our file server (by means of Java servlets). The result of such a search will be returned from Java servlet to XSL.
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 17017451
you should just need to take the protocol off the front of the url
and change first | to :

something like:

path = url.substring(8).replace('|', ':');
0
 

Author Comment

by:go4java
ID: 17018117
objects, could you pls. explain your rule on the URL given above:

file://///server/.../pdf/
0
 
LVL 92

Expert Comment

by:objects
ID: 17021421
you'll need different transformations depending on whether it contains a |
theres no standard way to do it as the url may not even point to a file.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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.

895 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

18 Experts available now in Live!

Get 1:1 Help Now