The Java implementation starts at the last line of the file read __java

Source: Internet
Author: User
Package Comz;
Import java.io.FileNotFoundException;
Import java.io.IOException;

Import Java.io.RandomAccessFile;
	public class FROMENDRF {public static void read (String filename) {read (filename, "GBK");
		public static void Read (string filename, string charset) {Randomaccessfile RF = null;
			try {rf = new Randomaccessfile (filename, "R");
			Long len = Rf.length ();
			Long start = Rf.getfilepointer ();
			Long NextEnd = start + len-1;
			String Line;
			Rf.seek (NextEnd);
			int c =-1;
				while (NextEnd > Start) {c = Rf.read ();
					if (c = = ' \ n ' | | c = = ' \ r ') {line = Rf.readline ();
					if (line!= null) {System.out.println (the new String (line. GetBytes ("Iso-8859-1"), CharSet));
					else {System.out.println (line);
				} nextend--;
				} nextend--;
				Rf.seek (NextEnd);
					if (NextEnd = = 0) {//When the file pointer is back to the beginning of the file, the output first line = Rf.readline (); System.out.println (New String (Line.getbytes ("iso-8859-1"), CharSet));
		A catch (FileNotFoundException e) {e.printstacktrace ());
		catch (IOException e) {e.printstacktrace ();
			Finally {try {if (RF!= null) rf.close ();
			catch (IOException e) {e.printstacktrace ();
	}} public static void Main (String args[]) {Read ("D:\\2.txt", "GBK"); }
}


Borrowed the code of old Zi Zhu.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.