Read about how to write data in file in java, The latest news, videos, and discussion topics about how to write data in file in java from alibabacloud.com
Here, both the read and write files in Java are based on the writable stream and mainly use the following classes:
1. FileReader ---- read the volume stream
2. FileWriter ---- write the volume stream
3. BufferedReader ---- buffer the input of a specified file
Methods of this class include:
Void close () to close the st
Article Source: http://www.cnblogs.com/wangcp-2014/p/5851986.html
Java, three ways to add content to a file
Import Java.io.BufferedWriter;
Import Java.io.FileOutputStream;
Import Java.io.FileWriter;
Import java.io.IOException;
Import Java.io.OutputStreamWriter;
Import Java.io.PrintWriter;
Import Java.io.RandomAccessFile;
If the file exists, append the content, or
ImportOrg.apache.avro.file.DataFileStream;5 ImportOrg.apache.avro.generic.GenericDatumReader;6 ImportOrg.apache.avro.generic.GenericRecord;7 Importorg.apache.hadoop.conf.Configuration;8 ImportOrg.apache.hadoop.fs.FileSystem;9 ImportOrg.apache.hadoop.fs.Path;Ten Importorg.apache.hadoop.io.IOUtils; One A Public classHdfsreadavro { - - the Public Static voidReadfromavro (InputStream is)throwsIOException { -datafilestreamNewDatafilestream(IS, - NewGenericdatumreader()); -
Java to write a. txt file, to implement several ways to wrap:1. Use the escape character "\ r \ n" in Java:
Java code
1. String str= "AAA";
2. str+= "\ r \ n";
So there's a line of change behind Str.Note: The order of \r,\n can not be exchanged, otherwise can not achieve the
Day20 read-write data in the Java language (i)I. Overview of IOIO data stream read and write function, in real life is also very common, such as file upload, download, automatic log updates and so on is closely related to IO read
Tag: ack Static red Write succeeds a try class catch PackageIO;ImportJava.io.BufferedWriter;ImportJava.io.FileWriter;Importjava.io.IOException; Public classWrite { Public Static voidMain (string[] args) {/*** File Write*/ Try{BufferedWriter out=NewBufferedWriter (NewFileWriter ("C:/hehe.txt"));//Create a Hehe.txt file
A Java file can contain multiple classes, but one of these classes has a special class whose properties are public and the name of the class is the same as the file name, and only one class in the Java file is public. InterfaceMoveable {voidrun ();}//Specific Product Roles c
an input stream file object AProp.load (in);//Load Input stream -System.out.println ("aa=" + prop.getproperty ("AA"));//aa=1 -Prop.setproperty ("AA", "11");//Modify the value of "AA" theOfile =NewFileOutputStream ("FilePath");//creating an output stream file object -Prop.store (Ofile, "");//saves properties of the Property object to the output stream specified file
"Go" Java read-write properties configuration file1.Properties class and properties configuration fileThe properties class inherits from the Hashtable class and implements the map interface, and it also holds the property set in the form of a key-value pair. However, the properties have a special place, that is, its keys and values are string types.2.main methods in the properties(1) Load (InputStream instr
[nbits (EV_MAX)];//supported event typesunsigned long keybit[nbits (KEY_MAX)];//supported key bitmapunsigned long relbit[nbits (Rel_max)];//bitmap that supports relative coordinatesunsigned long absbit[nbits (Abs_max)];//bitmap that supports absolute coordinatesunsigned long mscbit[nbits (Msc_max)];unsigned long ledbit[nbits (Led_max)];unsigned long sndbit[nbits (Snd_max)];unsigned long ffbit[nbits (Ff_max)];unsigned long swbit[nbits (Sw_max)];Writing a driver that conforms to the input subsyste
(2); FileOutputStream out=NewFileOutputStream (NewFile ("E:/a/a.jpg"));byte[] buf =New byte[1024x768];intlen=0; while((len=inch. Read (BUF))!=-1){ out. Write (BUF,0, Len); }inch. Close (); out. Close (); } con.close (); }Demo Result:Although the big data can be stored, but generally do not store big data, because the efficiency is too low, unless the
Because TestNG does not meet our display, so we will define a report, the implementation of the process is to do a static page, put in the Java project, in fact, and generate a log file similar, just the suffix, Java needs to use to PrintStream, the case is as follows, Static pages that I made in a static page This is implemented in the code by moving everything
In a multi-threaded program, if a shared file is to be accessed or edited, how can I read and write files in the exclusive mode?
Using java. NiO. channels. filelock is a good method. The idea is to first create a file named genfile. LCK,
The getchannel (). trylock () method returns a filelock. If no one accesses the
(")"));//Intercept to a numberI=integer.parseint (NUMSTR);//To calculate the number of the interceptionNewstr=i.tostring (); S=s.replaceall (Numstr, NEWSTR);//Replace the original number with the calculated numberResult.append (System.getproperty ("line.separator") +s); Sc.write (System.getproperty ("Line.separator") +s); } Else{result.append (System.getproperty ("Line.separator") +s); Sc.write (System.getproperty ("Line.separator") +s); }} br.close (); Sc.close
Java Read and Write properties configuration file
1.Properties class and properties configuration file
The properties class inherits from the Hashtable class and implements the map interface, and also holds the property set in the form of a key-value pair. But properties have a special place, that is, its keys and va
This article describes the Java file read and write and compression implementation method, the specific code is as follows:
Package Com.toone.iform.action.common;
Import Java.io.BufferedReader;
Import Java.io.BufferedWriter;
Import Java.io.File;
Import Java.io.FileInputStream;
Import java.io.FileNotFoundException;
Import Java.io.FileOutputStream;
Im
Write a string to a file:Code:
Import java. Io .*;
Class fileoutputdemo {
Public static void main (string ARGs []) {
Fileoutputstream out; // declare a file output object
Printstream P; // declare a print Stream Object
Try {
// Connected to "myfile.txt"
Out = new fileoutputstream ("C:/a.txt ");
// Connect print stream to the output stream
P = new p
comment information, and if blank, no comment information.The comment information is followed by the current save time information for the property file.(3) Getproperty/setpropertyThe two methods are to get and set property information, respectively.3. Code examplesThe properties file A.properties as follows:Name=rootpass=liukey=valueReads the A.properties property list, with the build properties
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.