All Downloads are FREE. Search and download functionalities are using the official Maven repository.

us.codecraft.webmagic.utils.FilePersistentBase Maven / Gradle / Ivy

The newest version!
package us.codecraft.webmagic.utils;

import java.io.File;

/**
 * Base object of file persistence.
 *
 * @author [email protected] 
* @since 0.2.0 */ public class FilePersistentBase { protected String path; public static String PATH_SEPERATOR = "/"; static { String property = System.getProperties().getProperty("file.separator"); if (property != null) { PATH_SEPERATOR = property; } } public void setPath(String path) { if (!path.endsWith(PATH_SEPERATOR)) { path += PATH_SEPERATOR; } this.path = path; } public File getFile(String fullName) { checkAndMakeParentDirecotry(fullName); return new File(fullName); } public void checkAndMakeParentDirecotry(String fullName) { int index = fullName.lastIndexOf(PATH_SEPERATOR); if (index > 0) { String path = fullName.substring(0, index); File file = new File(path); if (!file.exists()) { file.mkdirs(); } } } public String getPath() { return path; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy