本文整理汇总了Java中java.io.File.separator方法的典型用法代码示例。如果您正苦于以下问题:Java File.separator方法的具体用法?Java File.separator怎么用?Java File.separator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.File
的用法示例。
在下文中一共展示了File.separator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: saveMeta
import java.io.File; //导入方法依赖的package包/类
public void saveMeta(String id, ObservationResult cur) {
JsonObject meta = new JsonObject();
meta.add("start", cur.getStart().getTime());
meta.add("end", cur.getEnd().getTime());
if (cur.getGain() != null) {
meta.add("gain", cur.getGain());
}
if (cur.getChannelA() != null) {
meta.add("channelA", cur.getChannelA());
}
if (cur.getChannelB() != null) {
meta.add("channelB", cur.getChannelB());
}
File dest = new File(basepath, id + File.separator + "data" + File.separator + cur.getId() + File.separator + "meta.json");
try (BufferedWriter w = new BufferedWriter(new FileWriter(dest))) {
w.append(meta.toString());
} catch (IOException e) {
LOG.error("unable to write meta", e);
}
}
示例2: getSemaphoreFile
import java.io.File; //导入方法依赖的package包/类
/**
* returns the Semaphore File
*
* @return Semaphore File
*/
public File getSemaphoreFile() {
String fileStr = System.getProperty("java.io.tmpdir");
if (!fileStr.endsWith(File.separator)) {
fileStr += File.separator;
}
fileStr += ".kawansoft";
new File(fileStr).mkdir();
if (!fileStr.endsWith(File.separator)) {
fileStr += File.separator;
}
fileStr += "kawanfw-web-server-semaphore-port." + port;
return new File(fileStr);
}
示例3: getJavaRtPath
import java.io.File; //导入方法依赖的package包/类
public static String getJavaRtPath() {
File rtFile = new File(System.getProperty("java.home") +
File.separator + "lib" + File.separator + "rt.jar");
if (!rtFile.exists()) {
return null;
}
return rtFile.getAbsolutePath();
}
示例4: writeScripts
import java.io.File; //导入方法依赖的package包/类
/** write the scripts necessary to run the project */
public boolean writeScripts(boolean debug, boolean useBuildFileName) {
this.useBuildFileName = useBuildFileName;
//if (hasCBuild()) {
// System.out.println("The build.xml file is not being created, the user c-build.xml file is used instead.");
// return true; // if the user has a c-build.xml file, use his build
//}
try {
String script = Config.get().getTemplate("build-template.xml");
// replace <....>
script = replaceMarks(script, debug);
// create bin dir
File bindirfile = new File(project.getDirectory()+File.separator+bindir);
if (!bindirfile.exists()) {
bindirfile.mkdirs();
}
// write the script
FileWriter out = new FileWriter(project.getDirectory() + File.separator + bindir + getBuildFileName());
out.write(script);
out.close();
return true;
} catch (Exception e) {
System.err.println("Could not write start script for project " + project.getSocName());
e.printStackTrace();
return false;
}
}
示例5: getExtCacheDirectory
import java.io.File; //导入方法依赖的package包/类
public static String getExtCacheDirectory() {
String uacCachepath = TextUtils.isEmpty(getExtCacheDirectory("uac")) ? getExternalImageCacheDir(ContextUtils.getContext()) : getExtCacheDirectory("uac");
File photoFile = new File(uacCachepath);
if (!photoFile.exists()) {
photoFile.mkdir();
}
File nomediaFile = new File(uacCachepath + File.separator + ".nomedia");
if (!nomediaFile.exists()) {
nomediaFile.mkdir();
}
return uacCachepath;
}
示例6: updateOfFileReplace
import java.io.File; //导入方法依赖的package包/类
/**
* 文件替换的升级操作
* @param conf
*/
private void updateOfFileReplace(Map<String,Object> conf,String updateDir) throws IOException {
if(conf != null){
Set<String> keys = conf.keySet();//key是更新服务器上的文件
for (String key : keys) {
File updateFile = new File(updateDir + File.separator + key);
String targetFile = String.valueOf(conf.get(key));//value是需要替换的目标文件
targetFile = agentHome + File.separator + targetFile;
//删除需要替换的文件
Path targetPath = Paths.get(targetFile);
try(DirectoryStream<Path> stream = Files.newDirectoryStream(targetPath.getParent(),targetPath.getFileName().toString())){
for (Path path : stream) {
if(!path.toFile().delete()){
log.error("{}old file '{}' deleted <FAILED>. update <FAILED>",log4UpdateStart,path);
return;
}
}
}catch (Exception e){
log.error("",e);
}
FileUtils.copyFileToDirectory(updateFile,targetPath.getParent().toFile());
log.info("{}replace file '{}' to dir '{}' <SUCCESS>",log4UpdateStart,updateFile.toPath().getFileName(),targetPath.getParent());
}
}
}
示例7: deleteDirectory
import java.io.File; //导入方法依赖的package包/类
/**
* 删除目录(文件夹)以及目录下的文件
* <p>
* @param sPath 被删除目录的文件路径
* @return 目录删除成功返回true,否则返回false
*/
public static boolean deleteDirectory(String sPath) {
//如果sPath不以文件分隔符结尾,自动添加文件分隔符
if (!sPath.endsWith(File.separator)) {
sPath = sPath + File.separator;
}
File dirFile = new File(sPath);
//如果dir对应的文件不存在,或者不是一个目录,则退出
if (!dirFile.exists() || !dirFile.isDirectory()) {
return false;
}
flag = true;
//删除文件夹下的所有文件(包括子目录)
File[] fs = dirFile.listFiles();
for (File file : fs) {
//删除子文件
if (file.isFile()) {
flag = deleteFile(file.getAbsolutePath());
if (!flag) {
break;
}
} else { //删除子目录
flag = deleteDirectory(file.getAbsolutePath());
if (!flag) {
break;
}
}
}
if (!flag) {
return false;
}
//删除当前目录
return dirFile.delete();
}
示例8: testArchiveFileExists
import java.io.File; //导入方法依赖的package包/类
/**
* Tests that the configured archive file is created and exists.
*/
@Test
public void testArchiveFileExists() throws Exception {
final String dir = this.testDir.getAbsolutePath();
final String archiveFileName = dir + File.separator + this.testName.getMethodName() + ".gfs";
final File archiveFile1 =
new File(dir + File.separator + this.testName.getMethodName() + ".gfs");
Properties props = createGemFireProperties();
props.setProperty(STATISTIC_ARCHIVE_FILE, archiveFileName);
connect(props);
GemFireStatSampler statSampler = getGemFireStatSampler();
assertTrue(statSampler.waitForInitialization(5000));
final File archiveFile = statSampler.getArchiveFileName();
assertNotNull(archiveFile);
assertEquals(archiveFile1, archiveFile);
waitForFileToExist(archiveFile, 5000, 10);
assertTrue(
"File name incorrect: archiveFile.getName()=" + archiveFile.getName()
+ " archiveFile.getAbsolutePath()=" + archiveFile.getAbsolutePath()
+ " getCanonicalPath()" + archiveFile.getCanonicalPath(),
archiveFileName.contains(archiveFile.getName()));
}
示例9: init
import java.io.File; //导入方法依赖的package包/类
private void init() {
isRoot = RootUtil.isRoot();
if (!isRoot) {
tvRootStatus.setVisibility(View.VISIBLE);
return;
}
scriptStorePath = this.getCacheDir().getAbsolutePath();
ZipUtil.unzip(this.getPackageCodePath(), SCRIPT_NAME, scriptStorePath);
String cmd = "chmod 777 " + scriptStorePath + File.separator + Build.CPU_ABI + File.separator + SCRIPT_NAME;
RootUtil.execRootCmd(cmd);
}
示例10: add
import java.io.File; //导入方法依赖的package包/类
private void add(ChildData childData, boolean reload) throws IOException {
String name = childData.getPath().substring(childData.getPath().lastIndexOf("/") + 1);
byte[] data = childData.getData();
File file = new File(
SystemConfig.getHomePath() + File.separator + "conf",
name);
Files.write(data, file);
//try to reload dnindex
if (reload && "dnindex.properties".equals(name)) {
DbleServer.getInstance().reloadDnIndex();
}
}
示例11: openTextCache
import java.io.File; //导入方法依赖的package包/类
DataFileCache openTextCache(Table table, String source,
boolean readOnlyData,
boolean reversed) throws HsqlException {
closeTextCache(table);
if (!properties.isPropertyTrue(
HsqlDatabaseProperties.textdb_allow_full_path)) {
if (source.indexOf("..") != -1) {
throw (Trace.error(Trace.ACCESS_IS_DENIED, source));
}
String path = new File(
new File(
database.getPath()
+ ".properties").getAbsolutePath()).getParent();
if (path != null) {
source = path + File.separator + source;
}
}
TextCache c;
int type;
if (reversed) {
c = new TextCache(table, source);
} else {
c = new TextCache(table, source);
}
c.open(readOnlyData || filesReadOnly);
textCacheList.put(table.getName(), c);
return c;
}
示例12: createDir
import java.io.File; //导入方法依赖的package包/类
public static void createDir(String destDirName) {
final File dir = new File(destDirName);
if (dir.exists()) {// �ж�Ŀ¼�Ƿ����
// System.out.println("Target dir already existed");
}
if (!destDirName.endsWith(File.separator)) {// ��β�Ƿ���"/"����
destDirName = destDirName + File.separator;
}
if (dir.mkdirs()) {// ����Ŀ��Ŀ¼
System.out.println("Succeeded to create dir" + destDirName);
}
}
示例13: mergeCoverage
import java.io.File; //导入方法依赖的package包/类
private void mergeCoverage(File dir)
throws IOException
{
for (File f: interpreter.getSourceFiles())
{
File cov = new File(dir.getPath() + File.separator + f.getName() + ".cov");
LexLocation.mergeHits(f, cov);
println("Merged coverage for " + f);
}
}
示例14: renderCustomTypePaper
import java.io.File; //导入方法依赖的package包/类
@Test
public void renderCustomTypePaper() throws Exception {
// setup
config.setProperty("template.paper.file", "paper." + templateExtension);
DocumentTypes.addDocumentType("paper");
DBUtil.updateSchema(db);
Crawler crawler = new Crawler(db, sourceFolder, config);
crawler.crawl(new File(sourceFolder.getPath() + File.separator + "content"));
Parser parser = new Parser(config, sourceFolder.getPath());
Renderer renderer = new Renderer(db, destinationFolder, templateFolder, config);
String filename = "published-paper.html";
File sampleFile = new File(sourceFolder.getPath() + File.separator + "content" + File.separator + "papers" + File.separator + filename);
Map<String, Object> content = parser.processFile(sampleFile);
content.put(Crawler.Attributes.URI, "/" + filename);
renderer.render(content);
File outputFile = new File(destinationFolder, filename);
Assert.assertTrue(outputFile.exists());
// verify
String output = FileUtils.readFileToString(outputFile);
for (String string : getOutputStrings("paper")) {
assertThat(output).contains(string);
}
}
示例15: getDiskCacheDir
import java.io.File; //导入方法依赖的package包/类
/**
* 获取缓存目录
* @param mContext
* @param bitmap
* @return
*/
private File getDiskCacheDir(Context mContext, String bitmap) {
boolean externalStorageAvailable = Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
String cachePath;
if (externalStorageAvailable) {
cachePath = mContext.getExternalCacheDir().getPath();
} else {
cachePath = mContext.getCacheDir().getPath();
}
return new File(cachePath + File.separator + bitmap);
}