---
title: "grails ckeditor上传文件，中文名称乱码解决"
author: "icejadelove"
date: "2010-09-18T19:27:19Z"
tags: []
categories: ["编程语言"]
slug: "grails-ckeditor"
draft: false
lastmod: "2010-09-18T19:27:19Z"
id: 766668
url: "https://jdkdev.iteye.com/blog/766668"
---

打开grails插件目录，打开ckeditor，找到grails-app/controllers/org.gualdi.grails.plugins.ckeditor/StandardFileManagerConnectorController

然后找到里面的，文件保存代码：

```
if (FileUtils.isAllowed(f.ext, type)) {
```

```
                                /*修改上传文件的命名方式《下面这段代码为，自己添加的，用来改变文件命名方式，这样就可以解决中文乱码了》*/
                                SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssSSSS");
                                newName = formatter.format(new Date())+"."+f.ext;
```

```
                                def fileToSave = new File(finalDir, newName)
								if ( !overwrite ) {
									def idx = 1
									while (fileToSave.exists()) {
										errorNo = this.ERROR_FILE_RENAMED
										newName = "${f.name}(${idx}).${f.ext}"
										fileToSave = new File(finalDir, newName)
										idx++
									}
								}
								file.transferTo(fileToSave)
							}
							else {
								errorNo = this.ERROR_INVALID_FILE_TYPE
								errorMsg = "INVALID FILE TYPE"
							}
```