Results 1 to 6 of 6

Thread: Write a file without passing in arguments

  1. #1
    Join Date
    Dec 2009
    Posts
    292

    Write a file without passing in arguments

    Hello,
    I want to know how to write a file without passing in arguments. Let me explain: I would like to direct the file name. Txt instead of args [0]
    Code:
      Public static void hand(String args[]) throws IOException
      {
        PrintWriter wr;
        wr =  new PrintWriter(new BufferedWriter(args[0]));
    If you have a solution for this then I am interested , thanks for the help.

  2. #2
    Join Date
    Nov 2009
    Posts
    347

    Re: Write a file without passing in arguments

    Hello,
    This is in your post
    Code:
    Let me explain: I would like to direct the file name. Txt instead of args [0]
    You have given yourself the solution
    Code:
        writer =  new PrintWriter(new BufferedWriter("file.txt"));
    I hope you are understanding the things going on here, if not then you can read the documentation on the java.io package on the sun's official site. Read first and then do some programs in it.

  3. #3
    Join Date
    Dec 2009
    Posts
    296

    Re: Write a file without passing in arguments

    Hello,
    I am interested in the post and I have tried how to do this but I was not successful. I tested it but there's nothing written in file.txt
    Code:
      Public static void hand() throws IOException
      {
        PrintWriter wr;
        int n = 5;
        wr =  new PrintWriter(new BufferedWriter(new FileWriter("file.txt")));
       
        wr.System.out.println("hello, how goes it?");
        wr.close();
      }

  4. #4
    Join Date
    Nov 2009
    Posts
    330

    Re: Write a file without passing in arguments

    Hello,
    I think this is very simple and you should do it within few minutest, you can simply put the following code.
    Code:
     wr =  new PrintWriter(new BufferedWriter(new FileWriter("file.txt", true)));
    It means that we add text and false that replaces the one in your code. I hope you understood what I am trying to explain you. If you need any more help on this , that is regarding this topic then feel free to post.

  5. #5
    Join Date
    Nov 2009
    Posts
    356

    Re: Write a file without passing in arguments

    Hello,
    Code:
    It means that we add text and false that replaces
    I do not think so, true to say that we wrote at the end of the file, and false otherwise. You do not specify in the argument true, you write to each performance at the beginning of your file) What was there before, may be partially or completely crushed. So, you have to be careful when you are writing the code.

  6. #6
    Join Date
    Dec 2009
    Posts
    292

    Re: Write a file without passing in arguments

    Hello,
    I think I have solved my problem, by the way thanks for you help. I still have a little problem. at each execution of my program, which was in the file.txt file disappears. How to keep what is in the file? And also how to show the extension of the file. If you know how to do this then please help on with this. Thank you in advance.

Similar Threads

  1. Passing text from .cpp file to the Windows form
    By Zelman in forum Software Development
    Replies: 6
    Last Post: 28-06-2011, 10:50 AM
  2. Encryption of file before passing it over FTP.
    By Kapaali in forum Networking & Security
    Replies: 3
    Last Post: 09-05-2011, 07:06 PM
  3. Passing arguments to a function
    By Aman 1 in forum Software Development
    Replies: 3
    Last Post: 09-12-2009, 01:11 PM
  4. Passing "file" parameter in a function
    By kamina23 in forum Software Development
    Replies: 3
    Last Post: 29-10-2009, 11:07 PM
  5. Passing file from Gedit (unix) to Windows Notepad
    By KACY5 in forum Windows Software
    Replies: 3
    Last Post: 29-10-2009, 04:42 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,895,408.51814 seconds with 16 queries