-1

I have a image file stored in the resource folder.I am opening it and I am able to get its size but when I am printing it in string using string(size) it is showing special character(a square).I checked its type using reflect.Typeof(),it is giving int64.How to convert this to string and print the size as a string????

I am using the following code:

    imgFile,_ := os.Open("QrImgGA.png")
    fInfo, _ := imgFile.Stat()
    var size int64 = fInfo.Size()
    fmt.Println(string(size))//Prints the size correctl.Eg.,678899

But when I try to put it in json it shows some special character by doing the following:

    m:=make(map[string]string)
    m["bytes"]=string(size)
    js,_:=json.Marshal(m)
    fmt.Println(string(js))//Gives value as special character

Any suggestions?? or is there some another way of finding the size of an image???

peterSO
  • 158,998
  • 31
  • 281
  • 276

1 Answers1

1

Package strconv

import "strconv"

func FormatInt

func FormatInt(i int64, base int) string

FormatInt returns the string representation of i in the given base, for 2 <= base <= 36. The result uses the lower-case letters 'a' to 'z' for digit values >= 10.


For example,

package main

import (
    "fmt"
    "strconv"
)

func main() {
    size := int64(678899)
    str := strconv.FormatInt(size, 10)
    fmt.Println(str)
}

Output:

678899
peterSO
  • 158,998
  • 31
  • 281
  • 276