answersLogoWhite

0

// to create a new file

File f = new File("newfile.txt");

f.createNewFile();

// to write a string to a file

String str = "This text will appear in newfile.txt\nThis, too.";

// create our writer object

BufferedWriter out = new BufferedWriter(new FileWriter(f));

// write str to f

out.write(str);

// remember to flush the buffer and close the writer

out.flush();

out.close();

User Avatar

Wiki User

16y ago

What else can I help you with?

Continue Learning about Engineering

How do you create a File in Java?

There are a number of ways to create a file in java. The following example demonstrates a few: import java.io.*; import java.nio.charset.*; public class Main { public static void main(String[] args) { try { // Simplest way PrintWriter out1 = new PrintWriter("file1.txt"); out1.println("hello file1!"); out1.close(); // Append to existing file if it already exists PrintWriter out2 = new PrintWriter(new FileWriter("file2.txt", true)); out2.println("hello file2!"); out2.close(); // If non-default charset is needed Charset charset = Charset.forName("UTF-16"); PrintWriter out3 = new PrintWriter(new OutputStreamWriter(new FileOutputStream("file3.txt"), charset)); out3.println("hello file3!"); out3.close(); } catch (IOException e) { e.printStackTrace(); } } }


What is meant by read and write txt in file handling?

read: moving data from file to memory write: moving data from memory to file


How do you eliminate formatting lines from HTML files saved in Microsoft Word?

Microsoft word is not the best way to save HTML files for that very reason. However, one can select save as and then change the format of the file to "Text Only (*.txt)." Then all of the special formatting that MS word adds will be ignored and not saved.


In a command prompt what is the propose of a question mark in the file name?

It's a wildcard which means any single character. For instance: > dir ???.txt This will list all 3-letter file names that have a .txt extension in the current folder. An asterisk can also be used as a wildcard and represents any group of characters. > dir *.txt This will list all file names that have a .txt extension in the current folder.


How do you make a batch file to delete all files and folders in a particular folder?

The command is as follows : del c:\[directory you want to delete] /s This would need to be in a text file created in notepad, and saved as a .bat file. Or you could type EDIT from the command line to bring up the old DOS editor. Improving answer: Step 1: Open up Notepad Step 2: Type the following code in: @echo off deltree [Your hard drive, usually C:]\[Directory you want to delete /s for quietly Step 3: Save as "whateveryouwantwithoutquotes.bat"

Related Questions

What extension by default do files saved in Write use?

.txt


What are compression and archiving commands in Linux?

tar cvf archive.tar *.txt will create an archive called archive.tar with all the .txt files in the current directory. tar cvzf archive.tar.gz *.txt will create a compressed archive called archive.tar.gz


What is file is the text files?

.txt


What is a three letter word for files for computer?

txt


What is a basic text format your choices are wav txt vga or pdf?

The txt extension is used for text files.


What is the command to delete all files in the Adata folder that begin with the letter A and have the txt file extension?

DEL A:\data\ A*.txt


What is command required to return all files that end with a single digit and have the txt extension?

1s-1 myfile?.txt


Write the UNIX command to display the number of characters lines and words in the files myfile1txt myfile2txt and myfile3txt?

Use the 'wc' command: wc myfile[123].txt


Can't read the files on the disk?

I think would try to specify "files". Or you search for the ending of the files (.doc, .iso, .txt) on the interblogz.


Is there a simple way to combine multiple text files into 1 large text file in Windows?

Open a Command Prompt window, go to the folder where the files are (or you can use whole path names), and enter: COPY /A file1.txt + file2.txt + file3.txt + ... + lastfile.txt destination.txt /A


The file extension txt means the file is?

TXT files are plain text files. They are very basic documents with minimal formatting. They can be opened and edited with notepad, wordpad, or any other word processor application.


How do you make apple documents compatible with hp computers?

All files are already compatible like ZIP-files, DOC-files, TXT-files, Images etc