Java Byte Array Create toBytes(String s)

Here you can find the source of toBytes(String s)

Description

to Bytes

License

Apache License

Declaration

public static long toBytes(String s) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static long toBytes(String s) {
        long size = 0;
        if (s.endsWith("K") || s.endsWith("k")) {
            size = Long.valueOf(s.substring(0, s.length() - 1).trim()) * 1024;
        } else if (s.endsWith("M") || s.endsWith("m")) {
            size = Long.valueOf(s.substring(0, s.length() - 1).trim()) * 1024 * 1024;
        } else if (s.endsWith("G") || s.endsWith("g")) {
            size = Long.valueOf(s.substring(0, s.length() - 1).trim()) * 1024 * 1024;
        }//w  ww. j  a  v a2s .co m
        return size;
    }
}

Related

  1. toBytes(String hexStr)
  2. toBytes(String hexStr)
  3. toBytes(String hexString)
  4. toBytes(String hexString)
  5. toBytes(String name)
  6. toBytes(String s, int len, byte pad)
  7. toBytes(String str, byte[] bytes, int index)
  8. toBytes4(int n)
  9. toBytes4HexString(String str, char... separateds)