-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfile_utility.java
executable file
·104 lines (90 loc) · 2.69 KB
/
file_utility.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* file_utility.java
*
* Created on 21 òðàâíÿ 2008, 10:22
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package file_wrap;
import java.io.*;
/**
* Óòèëèòû äëÿ File
*/
public class file_utility {
private File field_file;
private String field_path_to_file;
/**
* @param path_to_file ïóòü ê ôàéëó
*/
public file_utility(String path_to_file) {
this.field_file=new File(path_to_file);
this.field_path_to_file=path_to_file;
}
/**
* Ïðîâåðèòü íà ñóùåñòâîâàíèå ôàéëà
*/
public boolean is_file_exists(){
return this.field_file.exists();
}
/**
* ïîëó÷èòü ïóòü ê ôàéëó (òîëüêî êàòàëîãè)
*/
public String get_directory(){
String return_value=this.field_file.getAbsolutePath();
return return_value.substring(0,return_value.length()-this.field_file.getName().length());
}
/**
* ïîëó÷èòü èìÿ ôàéëà ñ ðàñøèðåíèåì
*/
public String get_filename(){
return this.field_file.getName();
}
/**
* ïîëó÷èòü èìÿ ôàéëà áåç ðàñøèðåíèÿ
*/
public String get_filename_without_ext(){
String return_value=this.field_file.getName();
int dot_position=return_value.lastIndexOf(".");
if(dot_position>=0){
return return_value.substring(0,dot_position);
}else{
return return_value;
}
}
/**
* ïîëó÷èòü ðàñøèðåíèÿ ôàéëîâ
*/
public String get_extension(){
String return_value=this.field_file.getName();
int dot_position=return_value.lastIndexOf(".");
if(dot_position>=0){
return return_value.substring(dot_position+1);
}else{
return "";
}
}
/**
* ïîëó÷èòü ïîëíûé ïóòü ê ôàéëó
*/
public String get_full_path(){
return this.field_file.getAbsolutePath();
}
/**
* ïîëó÷èòü èìÿ ôàéëà, â êîòîðûé ìîæíî çàïèñàòü äàííûå, ïðè ÷åì ôàéë íå äîëæåí ñóùåñòâîâàòü
* @param path
* @param sufix
* ôàéë ñîñòîèò èç (path)+(filename)+(sufix)+(number)+(extension)
*/
public static String get_next_filename(String path,String sufix){
int counter=1;
file_utility file=new file_utility(path);
String directory=file.get_directory();
String file_name=file.get_filename_without_ext();
String file_ext=file.get_extension();
while (file.is_file_exists()==true){
file=new file_utility(directory+file_name+sufix+counter+"."+file_ext);
}
return file.get_full_path();
}
}