我正在尝试创建一个新的文件目录,但函数mkdir()
不起作用,mkdirs()
。
这是我的代码:
...
while (leitor.hasNext()){
String [] plv = LerPalavras(tamMem, leitor);
Arrays.sort(plv);
String nomeTemp = "/temp/temp" + contador + ".txt"; // I need to create this directory
try{
escritor = new FileWriter(nomeTemp);
for (int i = 0; i < tamMem; i++) {
escritor.write(plv[i] + " ");
}
escritor.close();
} catch (IOException e){
System.out.println(e.getMessage());
}
contador++;
}
...
编辑:我进行了编辑,现在它正在运作!
File pastaTemp = new File("/temp/temp");
pastaTemp.mkdirs();
while (leitor.hasNext()){
String [] plv = LerPalavras(tamMem, leitor);
Arrays.sort(plv);
File arqTemp = new File (pastaTemp, contador + ".txt");
try{
escritor = new FileWriter(arqTemp);
for (int i = 0; i < tamMem; i++) {
escritor.write(plv[i] + " ");
}
escritor.close();
} catch (IOException e){
System.out.println(e.getMessage());
}
contador++;
}
答案 0 :(得分:2)
尝试分两步完成。首先,如有必要,调用import base64
imgdata = base64.b64decode(new_string)
filename = 'image.jpg' # I assume you have a way of picking unique filenames
with open(filename, 'wb') as f:
f.write(imgdata)
创建整个目录结构,然后创建传递给 try:
convertedFileString = fstring.replace('-', '+').replace('_','/').replace(',','=')
imgdata = base64.b64decode(new_string)
# I assume you have a way of picking unique filenames
with open(filename, 'wb') as f:
s3 = boto3.resource('s3')
bucket = s3.Bucket('ag-grid')
bucket.put_object(Key=filename, Body=f)
except Exception as e:
return {
'statusCode': 500,
'body': str(e)
}
的文件:
File.mkdirs()