Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 678693
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:10:40+00:00 2026-05-14T01:10:40+00:00

There are some restricted characters (and even full filenames, in Windows), for file and

  • 0

There are some restricted characters (and even full filenames, in Windows), for file and directory names. This other question covers them already.

Is there a way, in Java, to retrieve this list of forbidden characters, which would be depending on the system (a bit like retrieving the line breaker chars)? Or can I only put the list myself, checking for the system?


Edit: More background on my particular situation, aside from the general question.

I use a default name, coming from some data (no real control over their content), and this name is given to a JFileChooser, as a default file name to use (with setSelectedFile()). However, this one truncates anything prior to the last invalid character.

These default names occasionally end with dates in a “mm/dd/yy” format, which leaves only the “yy”, in the default name, because “/” are forbidden. As such, checking for Exceptions is not really an option there, because the file itself is not even created yet.

Edit bis: Hmm, that makes me think, if JFileChooser is truncating the name, it probably has access to a list of such characters, can be interesting to check that further.

Edit ter: Ok, checking sources from JFileChooser shows something completely simple. For the text field, it uses file.getName(). It doesn’t actually check for invalid characters, it’s simply that it takes the “/” as a path separator, and keeps only the end, the “actual filename”. Other forbidden characters actually go through.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T01:10:41+00:00Added an answer on May 14, 2026 at 1:10 am

    When it comes to dealing with “forbidden” characters I’d rather be overcautious and ban/replace all “special” characters that may cause a problem on any filesystem.

    Even if technically allowed, sometimes those characters can cause weirdness.

    For example, we had an issue where the PDF files were being written (successfully) to a SAN, but when served up via a web server from that location some of the characters would cause issues when we were embedding the PDF in an HTML page that was being rendered in Firefox. It was fine if the PDF was accessed directly and it was fine in other browser. Some weird error with how Firefox and Adobe Reader interact.

    Summary: “Special” characters in file names -> weird errors waiting to happen

    Ultimately, the only way to be sure is to use a white-list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that there are some restricted api's or code that are not allowed
A UI question: is there some consensus on the best (defined as the one
I have this: <ul> <li> <p>Some long text here</p> </li> </ul> is there a
Are there some good resources tutorials or anyone has tried to implement a Capcha
Is there some way to define an abstract type as a parameter in an
Is there some kind of software that I can feed uploaded images to and
Is there some crucial difference in writing the registry class in MVC with magic
Is there some way to use Tuning Advisor for SQL Express? Is there some
Is there some event I can use to tell when the SelectedIndices property changes
Is there some regex that can be passed to re-seq such that it will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.