Example usage for java.io File separator

List of usage examples for java.io File separator

Introduction

In this page you can find the example usage for java.io File separator.

Prototype

String separator

To view the source code for java.io File separator.

Click Source Link

Document

The system-dependent default name-separator character, represented as a string for convenience.

Usage

From source file:Main.java

public static String getAndroidObbFolder(String packageName) {
    String path = Environment.getExternalStorageDirectory() + File.separator + "Android" + File.separator
            + "obb" + File.separator + packageName;
    return path;/*from  w ww  .  ja v  a2s. c  om*/
}

From source file:controller.NewEntryVideoControllerTest.java

@BeforeClass
public static void setUpClass() {
    String fSeparator = File.separator; //System.getProperty("file.separator");
    File file = new File(System.getProperty("user.dir") + fSeparator + "MyDiaryBook" + fSeparator + "Users"
            + fSeparator + "Panagiwtis Georgiadis" + fSeparator + "Entries" + fSeparator + "PAOK" + fSeparator
            + "Videos");
    file.mkdirs();//www  . jav a 2 s. co m
}

From source file:Main.java

public static String getFileName(String filePath) {
    if (TextUtils.isEmpty(filePath)) {
        return filePath;
    }/* w  w w  .  ja  v  a 2  s . c o m*/

    int filePosi = filePath.lastIndexOf(File.separator);
    return (filePosi == -1) ? filePath : filePath.substring(filePosi + 1);
}

From source file:Main.java

public static void copy(String source, String target, boolean isFolder) throws Exception {
    if (isFolder) {
        (new File(target)).mkdirs();
        File a = new File(source);
        String[] file = a.list();
        File temp = null;/*w w  w. j  a  v a  2  s  . co  m*/
        for (int i = 0; i < file.length; i++) {
            if (source.endsWith(File.separator)) {
                temp = new File(source + file[i]);
            } else {
                temp = new File(source + File.separator + file[i]);
            }
            if (temp.isFile()) {
                FileInputStream input = new FileInputStream(temp);
                FileOutputStream output = new FileOutputStream(target + "/" + (temp.getName()).toString());
                byte[] b = new byte[1024];
                int len;
                while ((len = input.read(b)) != -1) {
                    output.write(b, 0, len);
                }
                output.flush();
                output.close();
                input.close();
            }
            if (temp.isDirectory()) {
                copy(source + "/" + file[i], target + "/" + file[i], true);
            }
        }
    } else {
        int byteread = 0;
        File oldfile = new File(source);
        if (oldfile.exists()) {
            InputStream inStream = new FileInputStream(source);
            File file = new File(target);
            file.getParentFile().mkdirs();
            file.createNewFile();
            FileOutputStream fs = new FileOutputStream(file);
            byte[] buffer = new byte[1024];
            while ((byteread = inStream.read(buffer)) != -1) {
                fs.write(buffer, 0, byteread);
            }
            inStream.close();
            fs.close();
        }
    }
}

From source file:Main.java

public static String getFolderName(String filePath) {

    if (TextUtils.isEmpty(filePath)) {
        return filePath;
    }/*w ww  .  j ava 2  s. com*/

    int filePosi = filePath.lastIndexOf(File.separator);
    return (filePosi == -1) ? "" : filePath.substring(0, filePosi);
}

From source file:Main.java

public static void unpack(InputStream in, File targetDir) throws IOException {
    ZipInputStream zin = new ZipInputStream(in);
    ZipEntry entry;/*from   w  w w.ja  va  2s  .  c o m*/
    while ((entry = zin.getNextEntry()) != null) {
        String extractFilePath = entry.getName();
        if ((extractFilePath.startsWith("/")) || (extractFilePath.startsWith("\\"))) {
            extractFilePath = extractFilePath.substring(1);
        }
        File extractFile = new File(new StringBuilder().append(targetDir.getPath()).append(File.separator)
                .append(extractFilePath).toString());
        if (entry.isDirectory()) {
            if (!extractFile.exists())
                extractFile.mkdirs();
        } else {
            File parent = extractFile.getParentFile();
            if (!parent.exists()) {
                parent.mkdirs();
            }

            FileOutputStream os = new FileOutputStream(extractFile);
            copyFile(zin, os);
            os.flush();
            os.close();
        }
    }
}

From source file:Main.java

public static String getFileName(String filePath) {
    if (TextUtils.isEmpty(filePath)) {
        return "";
    }/*from  ww  w  . ja v a 2 s  . c  o  m*/

    int filePosi = filePath.lastIndexOf(File.separator);
    return (filePosi == -1) ? filePath : filePath.substring(filePosi + 1);
}

From source file:Main.java

public static String mergeFlockedFiles(String FilePath) {

    String result = null;/*from  w  w w . j  av  a  2 s .  c o  m*/
    try {
        result = java.net.URLDecoder.decode(FilePath, "UTF-8");
    } catch (UnsupportedEncodingException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
    }
    String fileName = result.substring(result.lastIndexOf('/') + 1);
    if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED)) {

        File flockedFilesFolder = new File(
                Environment.getExternalStorageDirectory() + File.separator + "FlockLoad");
        System.out.println("FlockedFileDir: " + flockedFilesFolder);
        long leninfile = 0, leng = 0;
        int count = 1, data = 0;
        int bytesRead = 0;
        try {
            File filename = new File(flockedFilesFolder.toString() + "/" + fileName);
            if (filename.exists())
                filename.delete();
            //BUFFER_SIZE = (int) filename.length();
            System.out.println("filename: " + filename);
            FileOutputStream fos = new FileOutputStream(filename, true);

            while (true) {
                File filepart = new File(filename + ".part" + count);
                System.out.println("part filename: " + filepart);
                if (filepart.exists()) {
                    FileInputStream fis = new FileInputStream(filepart);
                    byte fileBytes[] = new byte[(int) filepart.length()];
                    bytesRead = fis.read(fileBytes, 0, (int) filepart.length());
                    assert (bytesRead == fileBytes.length);
                    assert (bytesRead == (int) filepart.length());
                    fos.write(fileBytes);
                    fos.flush();
                    fileBytes = null;
                    fis.close();
                    fis = null;
                    count++;
                    filepart.delete();
                } else
                    break;
            }
            fos.close();
            fos = null;
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return fileName;
}

From source file:Main.java

/**
 * opens a FileChooser to select a file or folder if a folder is selected a
 * default filename is appended//from  w  ww  .  j  a  va  2 s  .co m
 *
 * @param c        parent
 * @param fileName default file name (in case a folder is selected)
 * @return null if nothing got selected, otherwise the absolute path
 */
@SuppressWarnings("SameParameterValue")
public static String openFileOrDirectoryWithDefaultFileName(Component c, File currentDirectory,
        String fileName) {
    File file = openJFileChooser(c, currentDirectory, JFileChooser.FILES_AND_DIRECTORIES, null);
    if (file == null) {
        return null;
    }
    String path = file.getAbsolutePath();
    if (file.isDirectory()) {
        if (path.endsWith(File.separator)) {
            path = path + fileName;
        } else {
            path = path + File.separator + fileName;
        }
    }
    return path;
}

From source file:Main.java

public static File getSaveFile(String folderPath, String fileNmae) {
    File file = new File(getSavePath(folderPath) + File.separator + fileNmae);
    try {/*from  w w  w .j  ava 2  s  .  c  o m*/
        file.createNewFile();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return file;
}