This is IntelliJ java. Create a /data/ directory in your project directory. Writ
ID: 3797200 • Letter: T
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. FileWriter can take a filename as an argument. The filename can only be a file in your current directory. So you can’t 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).
Here’s 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. I’ll 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 filesjava extfile.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! ]
Explanation / Answer
Just move the file directly to the project folder which calls "Java" (so the main folder) (next to the blue-blurred strip you made :P)
or if it doesn't help, then move the test123.txt file to FirstJavaProgram directory
you can also change filename to one of these:
1) src/test123.txt
2) FirstJavaProgram/src/test123.txt
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.