Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File path in java code in ubuntu

Tags:

java

ubuntu

I'm new in java and Ubuntu. I want to know how can i write the right path of specific file in code as i got exception like that

/home/me/javaException in thread "main" java.io.FileNotFoundException: 
home/me/java/config.properites (No such file or directory)

Here is my code:

public static void main(String[] args) {
    Properties prop = new Properties();
    String queryFile = null;
    FileOutputStream fos = null;
    try {
        // load a properties file
        FileInputStream finputstream = new FileInputStream("config.properties");
like image 629
user1 Avatar asked Sep 11 '26 11:09

user1


1 Answers

In ubuntu or any linux os your home folder is available in 'home/< username >'. You can check this from terminal or in gui. You can try some thing like,

File file = new File("/home/<your user name>/file.txt");
file.createNewFile();
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
like image 110
prit4fun Avatar answered Sep 13 '26 00:09

prit4fun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!