• 0

[Java] Filewriter directories


Question

package personstorage;

import java.util.*;

import java.io.*;

/**

*

* @author edmundsWP

*/

public class enterdetails {

static BufferedReader userInput =

new BufferedReader(new InputStreamReader(System.in));

public static void main(String[] args) throws IOException{

// TODO code application logic here

String name = null;

String surname = null;

System.out.println("Enter name please...");

name = userInput.readLine();

System.out.println("Enter surname please...");

surname = userInput.readLine();

System.out.println("Thank you " + name + ' ' + surname);

FileWriter file = new FileWriter( surname + ".txt");

BufferedWriter buffer = new BufferedWriter( file );

buffer.write(name);

buffer.newLine();

buffer.write(surname);

buffer.close();

}

}

bear with me im new to programming, this is working but it stores the file in the default program folder...

how might i go about using a folder named "contacts" or something within the program folder?

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0
bear with me im new to programming, this is working but it stores the file in the default program folder...

how might i go about using a folder named "contacts" or something within the program folder?

"blah" -> local directory

"../blah" -> up one level

"/contacts/blah"-> in contacts

Link to comment
Share on other sites

  • 0
"blah" -> local directory

"../blah" -> up one level

"/contacts/blah"-> in contacts

if he was on linux that would not work. /contacts/blah would start at the root of the directory hierarchy. If it is within the program folder, contacts/blah/ should work.

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.