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 8825015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:46:36+00:00 2026-06-14T06:46:36+00:00

import java.io.File; class AttriDemo{ public static void main(String args[]){ File f1 = new File(FileIO/file.txt);

  • 0
import java.io.File;
class AttriDemo{

    public static void main(String args[]){
        File f1 = new File("FileIO/file.txt");
        System.out.println("File name           : " + f1.getName());
        System.out.println("File path           : " + f1.getPath());
        System.out.println("File AbsPath        : " + f1.getAbsolutePath());
        System.out.println("File parent         : " + f1.getParent());
        f1.setWritable(true);
        if(f1.canWrite())
        {
            System.out.println("File is Writeable");
        }
        else
        {
            System.out.println("File is not Writeable");
        }
        if(f1.canRead())
        {
            System.out.println("Is readable");
        }
        else
        {
            System.out.println("File is not readable");
        }
    }
}

I the file is readable and writable in real…

then I tried setting it to Writable explicitly but still the output shows it as the file is not writable!!

output:

....
The file is not writable.
The file is not readable.

File f1 = new File("D:/javaProgs/FileIO/AttriDemo.java");

doing this helps solve the problem.
but can someone explain how? I mean the file was in the same directory and the statements above were running just fine. e.g getName() getParent()

  • 1 1 Answer
  • 0 Views
  • 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-06-14T06:46:37+00:00Added an answer on June 14, 2026 at 6:46 am

    What’s fooling you is you can create a File object regardless of the path you specified exists or not and you can call all those getParent, getPath functions on that object.

    You can create a File object that’s not backed by a real file for various reasons like to check if it exists or to create a file specified by that objects path and name.

    You can use File.exists() to see if file really exists on file system.

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

Sidebar

Related Questions

import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class InversionCounter { public static void main(String[]
import java.util.Scanner; public class CourseSplitter { public static void main(String args[]){ Scanner keyboard =
Unsure about static variables. import java.io.File; public class Logger { public static final File
This is my java file : import java.io.File; import java.lang.String; public class ListFiles {
One-Liner to list TXT-files. import java.io.File; import java.io.FilenameFilter; ... files = dir.listFiles(new FilenameFilter() {
import java.io.*; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class ExplicitChannelRead { /** * @param args
import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.jar.JarEntry; import java.util.jar.JarFile; public class
import java.io.*; public class Auto { /** * @param args * @throws IOException */
I created the following class located in the MainJPrint.java file import com.XXXXX.pdfPrint.PDFPrint; public class
Here's the class package db; import java.io.File; import java.io.FileInputStream; import java.sql.Connection; import java.sql.DriverManager; import

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.