Common tools and Java common small function implementation __linux

Source: Internet
Author: User
 
Import Java.io.File;

Import java.util.*; public class Readjpg {public static void main (String args[]) throws exception{vector<string> path=new vector&lt ;
		
		 String> ();
		 File root = new file ("E:/project/hand/midea");
		  Getjpg (Root,path);
		try {//path= (vector<string>) getjpg (Root). Clone ();
		catch (Exception e) {//TODO auto-generated catch block E.printstacktrace ();
		  }//System.out.println (Path.size ());
		  for (int i=0;i<path.size (); i++) {System.out.println (Path.get (i));
	 }/*usage * Read all JPG in the dir * intput:file dir * output:vector<string> Path; * * */FINAL static vector<string> getjpg (File dir, vector<string> Path) throws exception{//Vect
		  
		  or<string> vecstr = new vector<string> ();
		  file[] fs = Dir.listfiles ();
		   for (int i=0; i<fs.length; i++) {String name=fs[i].getname (); if (Name.endswith ("jpg")) {Path.add (fs[i].geTabsolutepath (). toString ());
		   System.out.println (Fs[i].getabsolutepath (). toString ());
		     
		    } if (Fs[i].isdirectory ()) {try{getjpg (Fs[i],path);
		}catch (Exception e) {}}}//System.out.println (Vecstr.size ());
	 return Path; }
}

public class ReadLine {public static void main (string[] args) {//TODO auto-generated method stub int linenumber=2
		;
           File Sourcefile=new file ("E:\\forread.txt");
               System.out.println ("Hello wolrd");  
            	   try {readappointedlinenumber (sourcefile, linenumber);  
            	   
               System.out.println (Gettotallines (sourcefile));
               }catch (IOException e) {e.printstacktrace ();  
	        } static void Readappointedlinenumber (File sourcefile, int linenumber) throws IOException {  
	        FileReader in = new FileReader (sourcefile);  
	        LineNumberReader reader = new LineNumberReader (in);  
	        String s = ""; if (linenumber <= 0 | | | linenumber > Gettotallines (sourcefile)) {System.out.println ("not in the number of lines of a file (1 to Total rows) Within.  
	            ");  
	        System.exit (0);  
	        int lines = 0; while (s!= null){lines++;  
	            s = Reader.readline ();  
	                if ((lines-linenumber) = = 0) {System.out.println (s);  
	            System.exit (0);  
	        } reader.close ();  
	    In.close ();  
	    The total number of rows in the//file contents.  
	        static int gettotallines (file file) throws IOException {FileReader in = new FileReader (file);  
	        LineNumberReader reader = new LineNumberReader (in);  
	        String s = reader.readline ();  
	        int lines = 0;  
	            while (s!= null) {lines++;  
	            s = Reader.readline ();  
	                if (lines>=2) {if (s!=null) {System.out.println (s+ "$");  
	        }} reader.close ();  
	        In.close ();  
	    return lines; }  
}

Import java.io.*; 
		public class Readname {public static void main (string[] args) throws IOException {//TODO auto-generated method stub
		int linenumber=2;
		
		String filepath= "E:\\bedroom\\richard_gere\\1.2\\1\\9\\9.618.jpg";
		System.out.println (Getworkid (FilePath));
		System.out.println (Getworkidandsequene (FilePath));
           System.out.println (MatchName ("E:\\forread.txt", "3.456"));
      
	System.out.println ("Hello wolrd");  }/* FilePath format for e:\\bedroom\\richard_gere\\1.2\\1\\9\\9.618.jpg * Get WorkID from given FilePath * Return WorkID */static string Getworkid (String FilePath) {string workid=null
	    	;
	    	String []s=filepath.split ("\\\\");
	        int temp=s.length-2;
	    	
			WORKID=S[TEMP];
	    	
	    return workid; }/* FilePath format for e:\\bedroom\\richard_gere\\1.2\\1\\9\\9.618.jpg * * Get WorkID and Se Quence from Given FilePath * * RetuRN format for WorkID.
	    	Sequence */static string Getworkidandsequene (String filePath) {string workidandsequene=null;
	    	String []s1=filepath.split ("\\\\");
	    	
	    	int temp=s1.length-1;
	    	String []s2=s1[temp].split ("\."); workidandsequene=s2[0]+ "."
			+S2[1];
	    return workidandsequene;
	     /* * Split WorkID and Sequence
	     * WorkID format for workid.sequence;
	     * Query WorkID and result from txtfile FilePath; */static string MatchName (String filepath,string workidandsequence) throws ioexception{String Name=null  
	    	;
	    	String []s1=workidandsequence.split ("\.");
	    	String Workid=s1[0];
	    	System.out.println ("wordkid=" +s1[0]);
	    	FileReader in =new FileReader (FilePath); 
	    	LineNumberReader reader = new LineNumberReader (in);  
	    	String str = reader.readline ();
			
	    		while (str!=null) {String []temp=str.split ("\\\\");
	    
	if (Temp[4].equals (WorkID))    			NAME=TEMP[1];
	    	Break
	    	} reader.close ();
	    	In.close ();
	    return Name; }
}

Import Java.io.FileOutputStream;
Pulic class savestringtotxt{public
	void Main (string []args) {
		string str= "Hello wolrd";
		FileOutputStream out =null;
    try{
    out=new fileoutputstream ("D:\\iotest\dest.txt", true);//Specify folder life and storage path
     out.write (str);
	 Out.close ();
	}


public static void Save2txt (String str; String FilePath) {
	  fileoutputstream out=new fileoutputstream (filepath,true);
	  Out.write (str);
	  Out.close ();
}


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.