请教有关于指定行数输出存档不覆盖要如何编写
各位好
请问这段代码指定行数输出后,自动存档不覆盖前一个已经储存的档案要如何编写?程序执行时,假设每输出230万行后,自动储存一个档案,取名档案A,又输出230万行自动储存一个档案,取名档B以此类推下去...
package main
import (
"fmt"
"math/big"
"os"
"github.com/btcsuite/btcd/btcec"
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcutil"
)
func main() {
// Initialise big numbers with small numbers
count, one := new(big.Int), big.NewInt(1)
count.SetString("15194206377246025674054756204990322111942063772460256740547562053972000", 10)
file, _ := os.Create("a.txt")
// Create a slice to pad our count to 32 bytes
padded := make([]byte, 32)
limit := 1 << 4
jops := make(chan *big.Int, 2*limit)
for i := 0; i < limit; i++ {
go worker(jops, padded, file)
}
// Loop forever because we're never going to hit the end anyway
for {
// Increment our counter
count.Add(count, one)
jops <- count
}
}
func worker(jops <-chan *big.Int, padded []byte, file *os.File) {
for count := range jops {
// Copy count value's bytes to padded slice
copy(padded[32-len(count.Bytes()):], count.Bytes())
// Get public key
_, public := btcec.PrivKeyFromBytes(btcec.S256(), padded)
// Get compressed and uncompressed addresses
caddr, _ := btcutil.NewAddressPubKey(public.SerializeCompressed(), &chaincfg.MainNetParams)
uaddr, _ := btcutil.NewAddressPubKey(public.SerializeUncompressed(), &chaincfg.MainNetParams)
// Print keys
row := fmt.Sprintf("%x\n%34s\n%34s\n", padded, uaddr.EncodeAddress(), caddr.EncodeAddress())
fmt.Print(row)
fmt.Fprint(file, row)
}
}
@omega 你再看一下,应该不会重复了。