What is the simplest way to create file in java? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

What is the simplest way to create file in java?

FTLFTL Posts: 3Member
edited January 2014 in Java

I tried

import java.io.*;
public class file1
{
  public static void main(String[] args)
  {

    File text1 = new File("C:\text1.txt");

}

then I tried

import java.io.*;
public class file1
{
  public static void main(String[] args)
  {

    //File text1 = new File("C:\text1.txt");
    try
    {
    FileWriter file = new FileWriter("C:\text1.txt");

    }
    catch(Exception e)
    {}

    }
})

then I tried

    import java.io.*;
    public class file1
    {
      public static void main(String[] args)
      {

         try
        {
        FileWriter file = new FileWriter("C:\text1.txt");
        BufferedWriter bw= new BufferedWriter(file);

        bw.write("  ");
        bw.close();

        }
        catch(Exception e)
        {}

        }
    }

None of these seem to create a file called text1.txt in C:\ when I run it.
How exactly do I create a real file in C:\ ?

Sign In or Register to comment.