Issue With File Searching

J

jagadesh

Hi Guys,

iam working on a file upload sort of application.my issue i need to
search files in a folder.for example i will be storing all the filed
uploaded in a folder called "data files". so if i upload file with
name (will be given by user)file1.java . first i need to check
whether a file with name file1.java already exists.if so then i need
to rename the uploaded file with file2.java . how can i do this.


Can anyone sort me out please.

thank u,
jagadesh
 
J

John B. Matthews

jagadesh said:
am working on a file upload sort of application. [M]y issue:
need to search files in a folder. [F]or example, will be storing
all the file uploaded in a folder called "data files". o if
upload [a] file with [the] name file1.java, [which] will be given by
[the] user, need to check whether a file with name file1.java
already exists. f so, then need to rename the uploaded file
[as] file2.java. [H]ow can do this.


I'd search the array returned by File#listFiles() or test File#exists()
for the first step:

<http://java.sun.com/javase/6/docs/api/java/io/File.html>

I'd adopt (or create) a standard for the second.

I see my OS vendor does something like this:

Dissect and retain any extension.
Insert (or increment) dash + number.
Trim to maximum name length - extension length.
Re-attach extension.

Here's a recent example, with a fictitious base name:

foo-1.0.15.tar.gz
foo-1-1.0.15.tar.gz
foo-1-2.0.15.tar.gz
foo-1-3.0.15.tar.gz

It's not perfect.
 
R

Roland Pibinger

iam working on a file upload sort of application.my issue i need to
search files in a folder.for example i will be storing all the filed
uploaded in a folder called "data files". so if i upload file with
name (will be given by user)file1.java . first i need to check
whether a file with name file1.java already exists.if so then i need
to rename the uploaded file with file2.java . how can i do this.

Take a look at File.createNewFile(). It does the checks for you:
http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html#createNewFile()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top