checking valid filename

Discussion in 'Java' started by Alex, Jan 31, 2004.

  1. Alex

    Alex Guest

    How do I check if a filename is valid in java i.e. if it has the permitted
    characters of a filename?
     
    Alex, Jan 31, 2004
    #1
    1. Advertising

  2. Alex

    hiwa Guest

    "Alex" <> wrote in message news:<bvh3ah$6vi$>...
    > How do I check if a filename is valid in java i.e. if it has the permitted
    > characters of a filename?

    FileFilter or FileNameFilter. For example, you can get filtered file
    name list via File#list(FileNameFilter) method.
     
    hiwa, Feb 2, 2004
    #2
    1. Advertising

  3. Alex

    Alex Guest

    I probably didn't make my question specific enough...

    How do I test if a filename is accepted by the local file system?

    - For example a file with filename "1aa" will not be accepted in windows
    because it starts
    with a number.




    "hiwa" <> wrote in message
    news:...
    > "Alex" <> wrote in message

    news:<bvh3ah$6vi$>...
    > > How do I check if a filename is valid in java i.e. if it has the

    permitted
    > > characters of a filename?

    > FileFilter or FileNameFilter. For example, you can get filtered file
    > name list via File#list(FileNameFilter) method.
     
    Alex, Feb 2, 2004
    #3
  4. Alex

    Alex Guest

    bad example....

    a file with filename "aa?" will not be accepted 'cos it has a question mark



    "Alex" <> wrote in message
    news:bvl116$nbp$...
    > I probably didn't make my question specific enough...
    >
    > How do I test if a filename is accepted by the local file system?
    >
    > - For example a file with filename "1aa" will not be accepted in windows
    > because it starts
    > with a number.
    >
    >
    >
    >
    > "hiwa" <> wrote in message
    > news:...
    > > "Alex" <> wrote in message

    > news:<bvh3ah$6vi$>...
    > > > How do I check if a filename is valid in java i.e. if it has the

    > permitted
    > > > characters of a filename?

    > > FileFilter or FileNameFilter. For example, you can get filtered file
    > > name list via File#list(FileNameFilter) method.

    >
    >
     
    Alex, Feb 2, 2004
    #4
  5. Alex schrieb:

    > I probably didn't make my question specific enough...
    >
    > How do I test if a filename is accepted by the local file system?
    >
    > - For example a file with filename "1aa" will not be accepted in windows
    > because it starts
    > with a number.
    >


    Windows does accept a file with the name "1aa" ...

    The only way I can see, is to create the file physically on the disk - using
    File.createNewFile() - and check any exception.


    Thomas
     
    Thomas Kellerer, Feb 2, 2004
    #5
  6. Alex

    Alex Guest

    Yes that's what I think I'll have to do - even though I don't consider that
    'good' programming practice. I was hoping java would have something better
    in the API. I'm writing an app which will write to Linux and Windows
    partitions at the same time so it needs to check for both OSes.


    "Thomas Kellerer" <> wrote in message
    news:bvl2t4$tsjqq$-berlin.de...
    > Alex schrieb:
    >
    > > I probably didn't make my question specific enough...
    > >
    > > How do I test if a filename is accepted by the local file system?
    > >
    > > - For example a file with filename "1aa" will not be accepted in windows
    > > because it starts
    > > with a number.
    > >

    >
    > Windows does accept a file with the name "1aa" ...
    >
    > The only way I can see, is to create the file physically on the disk -

    using
    > File.createNewFile() - and check any exception.
    >
    >
    > Thomas
     
    Alex, Feb 2, 2004
    #6
  7. Alex

    nos Guest

    "Alex" <> wrote in message
    news:bvl43o$pdo$...
    > Yes that's what I think I'll have to do - even though I don't consider

    that
    > 'good' programming practice. I was hoping java would have something better
    > in the API. I'm writing an app which will write to Linux and Windows
    > partitions at the same time so it needs to check for both OSes.


    How about something like this?

    try
    {
    File f = new File("a??");
    }
    catch .......
     
    nos, Feb 3, 2004
    #7
  8. Alex

    Jon A. Cruz Guest

    Alex wrote:
    > bad example....
    >
    > a file with filename "aa?" will not be accepted 'cos it has a question mark
    >


    I've made those before. And files with "*", and files with "\", and
    files starting with "C:\", all on Linux/Unix systems.
     
    Jon A. Cruz, Feb 8, 2004
    #8
  9. Alex

    Jon A. Cruz Guest

    Alex wrote:
    > Yes that's what I think I'll have to do - even though I don't consider that
    > 'good' programming practice. I was hoping java would have something better
    > in the API. I'm writing an app which will write to Linux and Windows
    > partitions at the same time so it needs to check for both OSes.
    >


    Even on a single OS, the allowed file names can change per filesystem of
    partitions.

    FAT vs NTFS is one big difference.
     
    Jon A. Cruz, Feb 8, 2004
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Sm9l?=

    Extract filename from a filename typed by user

    =?Utf-8?B?Sm9l?=, Aug 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,068
    Travis Murray
    Aug 24, 2004
  2. Replies:
    1
    Views:
    1,600
    Roland de Ruiter
    Jun 15, 2006
  3. Ed
    Replies:
    10
    Views:
    46,702
    alok000707
    Jul 13, 2010
  4. Beauregard T. Shagnasty

    Re: filename.gif or filename.gif.jpg?

    Beauregard T. Shagnasty, May 30, 2008, in forum: HTML
    Replies:
    1
    Views:
    809
    Jonathan N. Little
    May 30, 2008
  5. Replies:
    4
    Views:
    138
    Mick White
    Feb 25, 2005
Loading...

Share This Page