Java Code Examples for java.io.File.separator()

The following are Jave code examples for showing how to use separator() of the java.io.File class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: r2cloud   File: SatelliteDao.java   View Source Code Vote up 6 votes
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);
	}
}
 
Example 2
Project: aceql-http   File: PortSemaphoreFile.java   View Source Code Vote up 6 votes
/**
    * 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);
   }
 
Example 3
Project: MeziLang   File: PathUtil.java   View Source Code Vote up 5 votes
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();
}
 
Example 4
Project: code-sentinel   File: CentralisedMASLauncherAnt.java   View Source Code Vote up 5 votes
/** 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;
    }
}
 
Example 5
Project: letv   File: SystemUtils.java   View Source Code Vote up 5 votes
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;
}
 
Example 6
Project: SuitAgent   File: Update.java   View Source Code Vote up 5 votes
/**
 * 文件替换的升级操作
 * @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());
        }
    }
}
 
Example 7
Project: PackagePlugin   File: FileUtil.java   View Source Code Vote up 5 votes
/**
 * 删除目录(文件夹)以及目录下的文件
 * <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();
}
 
Example 8
Project: monarch   File: GemFireStatSamplerIntegrationTest.java   View Source Code Vote up 5 votes
/**
 * 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()));
}
 
Example 9
Project: dex-hdog   File: MainActivity.java   View Source Code Vote up 5 votes
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);
}
 
Example 10
Project: dble   File: BinDataPathChildrenCacheListener.java   View Source Code Vote up 5 votes
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();
    }
}
 
Example 11
Project: parabuild-ci   File: Log.java   View Source Code Vote up 5 votes
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;
}
 
Example 12
Project: SpotSpotter   File: FileOperation.java   View Source Code Vote up 5 votes
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);
	}
}
 
Example 13
Project: FJ-VDMJ   File: CommandReader.java   View Source Code Vote up 5 votes
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);
  	}
  }
 
Example 14
Project: jbake-rtl-jalaali   File: GroovyMarkupTemplateEngineRenderingTest.java   View Source Code Vote up 5 votes
@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);
    }

}
 
Example 15
Project: DailyStudy   File: ImageLoader.java   View Source Code Vote up 5 votes
/**
 * 获取缓存目录
 * @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);
}
 
Example 16
Project: crush   File: Scuba2Subscan.java   View Source Code Vote up 5 votes
public void setJCMTTableTau() throws Exception {
	String source = hasOption("tau.jctables") ? option("tau.jctables").getPath() : ".";
	String spec = scan.getShortDateString();
	String fileName = source + File.separator + spec + ".jcmt-183-ghz.dat";
	
	try {
		JCMTTauTable table = JCMTTauTable.get((int) scan.getMJD(), fileName);
		table.setOptions(option("tau"));
		setTau("183ghz", table.getTau(getMJD()));	
	}
	catch(IOException e) { fallbackTau("jctables", e); }
}
 
Example 17
Project: ripme   File: Utils.java   View Source Code Vote up 4 votes
private static String getConfigFilePath() {
    return getConfigDir() + File.separator + configFile;
}
 
Example 18
Project: crush   File: Scuba2Fits.java   View Source Code Vote up 4 votes
private File fromSDF(String sdfName) throws IOException, FileNotFoundException {
	// If it's an SDF, check if an equivalent FITS exists also...
	// If so, then we can skip the SDF, and wait for the FITS to be read...
	File fitsFile = new File(getFitsName(sdfName));
	if(fitsFile.exists()) return fitsFile;
				
	File sdf = new File(sdfName);
	if(!sdf.exists()) throw new FileNotFoundException("SDF file '" + sdfName + "' not found."); 
				
	if(!options.isConfigured("ndf2fits")) 
		throw new FileNotFoundException("Please set path to 'ndf2fits' with the 'ndf2fits' option. E.g.\n"
				+ "  ndf2fits = /usr/local/starlink/bin/ndf2fits\n");
	
	String inName = sdf.getAbsolutePath();
	String command = options.get("ndf2fits").getValue();
	String outName = sdf.getParentFile().getPath() + File.separator + getFitsName(sdf.getName());
	
	Runtime runtime = Runtime.getRuntime();

	String commandLine = command + " " + inName + " " + outName + " proexts";
	String[] commandArray = { command, inName, outName, "proexts" };

	CRUSH.info(this, "Converting SDF to FITS...");
	CRUSH.info(this, "> " + commandLine);

	Process convert = runtime.exec(commandArray); 
	//BufferedReader err = new BufferedReader(new InputStreamReader(convert.getErrorStream()));

	//String line = null;
	//while((line = err.readLine()) != null) CRUSH.debug(this, line);

	try { 
		int retval = convert.waitFor(); 
		if(retval != 0) {
			CRUSH.warning(this, "Conversion error. Check that 'ndf2fits' is correct, and that "
			        + "the 'datapath' directory is writeable.");
			//if(outFile.exists()) outFile.delete();
			throw new IOException("SDF to FITS conversion error.");
		}
		return new File(outName);
	}
	catch(InterruptedException e) {
		CRUSH.warning(this, "Interrupted!");
		System.exit(1);
	}

	return null;
}
 
Example 19
Project: Cognizant-Intelligent-Test-Scripter   File: TestCase.java   View Source Code Vote up 4 votes
public String getLocation() {
    return scenario.getLocation() + File.separator + name + ".csv";
}
 
Example 20
Project: javaide   File: ProjectCreator.java   View Source Code Vote up 3 votes
/**
 * Installs a new file that is based on a template file provided by a given target.
 * Each match of each key from the place-holder map in the template will be replaced with its
 * corresponding value in the created file.
 *
 * @param templateName the name of to the template file
 * @param destFile the path to the destination file, relative to the project
 * @param placeholderMap a map of (place-holder, value) to create the file from the template.
 * @param target the Target of the project that will be providing the template.
 * @throws ProjectCreateException
 */
private void installTargetTemplate(String templateName, File destFile,
        Map<String, String> placeholderMap, IAndroidTarget target)
        throws ProjectCreateException {
    // query the target for its template directory
    String templateFolder = target.getPath(IAndroidTarget.TEMPLATES);
    final String sourcePath = templateFolder + File.separator + templateName;

    installFullPathTemplate(sourcePath, destFile, placeholderMap);
}