GithubHelp home page GithubHelp logo

Comments (4)

sampottinger avatar sampottinger commented on September 18, 2024

There is an open issue at https://bugs.openjdk.java.net/browse/JDK-8187981 but it doesn't seem to be getting much traction. There is an alternative to System.getProperty but it's through swing:

import java.io.FileNotFoundException;
import javax.swing.filechooser.FileSystemView;


void setup() {
  
  // Use file view to get directories
  FileSystemView view = FileSystemView.getFileSystemView();
  File homeDirectory = view.getHomeDirectory();
  
  // Try writing to home directory
  File testHomeFile = view.createFileObject(homeDirectory, "test_home.txt");
  try {
    PrintWriter writer = new PrintWriter(testHomeFile);
    writer.print("test home");
    writer.close();
  } catch (FileNotFoundException e) {
    println("File not found exception on documents.");
  }
  
  // Try writing to documents directory
  File documentsDirectory = view.getChild(homeDirectory, "Documents");
  File testDocumentsFile = view.createFileObject(documentsDirectory, "test_docs.txt");
  try {
    PrintWriter writer = new PrintWriter(testDocumentsFile);
    writer.print("test documents");
    writer.close();
  } catch (FileNotFoundException e) {
    println("File not found exception on documents.");
  }
  
}

See https://gist.github.com/sampottinger/49aef03638b150257cca919954319f01. It does work on 10.14 with a signed application.

Open to suggestions but, unfortunately, JDK 11 isn't providing an alternative as far as I can tell? @benfry - would you like me to switch out for FileSystemView or leave this ticket as is and address in a future JDK?

from processing4.

benfry avatar benfry commented on September 18, 2024

I think FileSystemView would be a step backwards, so we should leave it open until we have a better fix. (Want to get AWT/Swing out of there wherever possible.)

Might be something we just need to add via JNA, since it should be a single OS call.

from processing4.

sampottinger avatar sampottinger commented on September 18, 2024

I agree. :(

from processing4.

benfry avatar benfry commented on September 18, 2024

Since this was originally posted, I've been hearing that using the name works, and the localization is handled transparently, perhaps suggesting that it's a more stable way to handle this than expected. macOS may do all sorts of “container” things behind the scenes, but it's maybe less of a concern than I originally thought.

I don't love it, but this is at least a lower priority in that case.

Also making a note in MacPlatform to reference this issue.

from processing4.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.