Question
This is IntelliJ java. Create a /data/ directory in your project directory. Write a program that creates and stores a test file in this directory.
This is IntelliJ java.
Create a /data/ directory in your project directory. Write a program that creates and stores a test file in this directory. FileWriter can take a filename as an argument. The filename can only be a file in your current directory. So you cant say new FileWriter fw = new FileWriter(/data/testing.txt);But, FileWriter can also take a File object as an argument, and a File object can store a path to a file elsewhere on your system (or even on a remote system).
Heres how to create a File object; File f = new File(/mydirectory/mysubdirectory/textfile.txt);
Assuming these directories exist, you can create and write that file in this location. The location is relative to the current directory. Ill leave it to you to put these pieces together.Notice that one file system uses forward slashes, and one uses backslashes, so you'll need to use the correct \ or / for your computer. Mac is also case-sensitive.[Note: You can also use absolute pathnames, for example
C:\program files\java\textfile.txt on Windows, or/users/admin/Documents/textfile.txt on a Unix-based system like Linux or Mac,
but if you do that, your program may not work on anyone else's computer! ]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started