出于某些奇怪的原因,我不断遇到不同类型的Android设备的问题,用于将捕获的图像保存在设备存储上.
这里是详细的错误日志,实际上是什么.
java.io.IOException: open failed: EACCES (Permission denied)
at java.io.File.createNewFile(File.java:940)
at com.parkhya.pick_for_shareAflash.HomeActivity.resizeImage(HomeActivity.java:456)
at com.parkhya.pick_for_shareAflash.HomeActivity.onActivityResult(HomeActivity.java:393)
Caused by: libcore.io.ErrnoException: open failed: EACCES (Permission denied)
at java.io.File.createNewFile(File.java:933)
Run Code Online (Sandbox Code Playgroud)
虽然,所有其他Android应用程序,如Instagram和其他人,都可以保存设备上的相机点击图像.任何人,请你建议,为了我的应用程序,我应该怎么做,将相机图片保存在SD卡中.
Firebase 服务出现以下错误。
E/FirebaseInstanceId: Topic sync or token retrieval failed on hard failure exceptions: FIS_AUTH_ERROR. Won't retry the operation.
D/AndroidRuntime: Shutting down VM
com.google.android.gms.tasks.RuntimeExecutionException: java.io.IOException: FIS_AUTH_ERROR
at com.google.android.gms.tasks.zzu.getResult(Unknown Source:15)
at com.myApp.MainActivity$2.onComplete(MainActivity.java:349)
at com.google.android.gms.tasks.zzj.run(Unknown Source:4)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:237)
at android.app.ActivityThread.main(ActivityThread.java:7804)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1068)
Caused by: java.io.IOException: FIS_AUTH_ERROR
at com.google.firebase.iid.zzs.zza(com.google.firebase:firebase-iid@@20.1.0:82)
at com.google.firebase.iid.zzs.zza(com.google.firebase:firebase-iid@@20.1.0:96)
at com.google.firebase.iid.zzx.then(com.google.firebase:firebase-iid@@20.1.0:4)
at com.google.android.gms.tasks.zzd.run(Unknown Source:5)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
at java.lang.Thread.run(Thread.java:919)
Run Code Online (Sandbox Code Playgroud)
这是发生崩溃的代码部分:
FirebaseInstanceId.getInstance().getInstanceId().addOnCompleteListener(new OnCompleteListener<InstanceIdResult>() {
@Override
public void onComplete(@NonNull Task<InstanceIdResult> task) {
if (task.getResult() …Run Code Online (Sandbox Code Playgroud) 我的代码是这样的:
URL url;
URLConnection uc;
StringBuilder parsedContentFromUrl = new StringBuilder();
String urlString="http://www.example.com/content/w2e4dhy3kxya1v0d/";
System.out.println("Getting content for URl : " + urlString);
url = new URL(urlString);
uc = url.openConnection();
uc.connect();
uc.getInputStream();
BufferedInputStream in = new BufferedInputStream(uc.getInputStream());
int ch;
while ((ch = in.read()) != -1) {
parsedContentFromUrl.append((char) ch);
}
System.out.println(parsedContentFromUrl);
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试通过浏览器访问URL时没有问题,但是当我尝试通过java程序访问它时,它会抛出预期:
java.io.IOException: Server returned HTTP response code: 403 for URL
Run Code Online (Sandbox Code Playgroud)
解决办法是什么?
我试图在文件系统上创建一个文件,但我一直得到这个例外:
java.io.IOException: No such file or directory
Run Code Online (Sandbox Code Playgroud)
我有一个现有的目录,我正在尝试将文件写入该目录.
// I have also tried this below, but get same error
// new File(System.getProperty("user.home") + "/.foo/bar/" + fileName);
File f = new File(System.getProperty("user.home") + "/.foo/bar/", fileName);
if (f.exists() && !f.canWrite())
throw new IOException("Kan ikke skrive til filsystemet " + f.getAbsolutePath());
if (!f.isFile()) {
f.createNewFile(); // Exception here
} else {
f.setLastModified(System.currentTimeMillis());
}
Run Code Online (Sandbox Code Playgroud)
获得例外:
java.io.IOException: No such file or directory
at java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(File.java:883)`
Run Code Online (Sandbox Code Playgroud)
我对路径有写权限,但是没有创建文件.
我是android的新手,这是我在android上的第一个项目.我在"认证"问题上苦苦挣扎了一天多.我尝试了几个选项,但没有一个可行.
基本上,我想调用REST API并获得响应.我确信API中没有问题,因为我在另一个iOS应用程序中使用相同的API.
我传递授权标题但仍然显示身份验证未找到消息.我发现与stackoverflow相关的问题很少,但是其中一些没有用,有些对我没有意义.
我得到状态代码401.我知道这意味着要么没有传递身份验证,要么传递,那么它们就错了.在这里,我确信我传递的是正确的.
以下是我的代码:
try {
url = new URL(baseUrl);
}
catch (MalformedURLException me) {
Log.e(TAG, "URL could not be parsed. URL : " + baseUrl + ". Line : " + getLineNumber(), me);
me.printStackTrace();
}
try {
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod(method);
urlConnection.setConnectTimeout(TIMEOUT * 1000);
urlConnection.setChunkedStreamingMode(0);
// Set HTTP headers
String authString = "username:password";
String base64Auth = Base64.encodeToString(authString.getBytes(), Base64.DEFAULT);
urlConnection.setRequestProperty("Authorization", "Basic " + base64Auth);
urlConnection.setRequestProperty("Accept", "application/json");
urlConnection.setRequestProperty("Content-type", "application/json");
if (method.equals("POST") || method.equals("PUT")) {
// Set …Run Code Online (Sandbox Code Playgroud) 这是我目前的代码:
public class FileStatus extends Status{
FileWriter writer;
public FileStatus(){
try {
writer = new FileWriter("status.txt",true);
} catch (IOException e) {
e.printStackTrace();
}
}
public void writeToFile(){
String file_text= pedStatusText + " " + gatesStatus + " " + DrawBridgeStatusText;
try {
writer.write(file_text);
writer.flush();
writer.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
一切都按预期工作(文件在调用writeToFile方法时写入).但是当第二次调用writeToFile方法时,我收到以下错误:
java.io.IOException: Stream closed
at sun.nio.cs.StreamEncoder.ensureOpen(StreamEncoder.java:45)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:118)
at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:135)
at java.io.OutputStreamWriter.write(OutputStreamWriter.java:220)
at java.io.Writer.write(Writer.java:157)
at FileStatus.writeToFile(FileStatus.java:19)
at MenuBar$9.actionPerformed(MenuBar.java:115)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at …Run Code Online (Sandbox Code Playgroud) 目前我正在编写一个将要监听目录的代码.当使用.apk文件更新目录时,我会将带有此.apk文件的邮件发送到gmail帐户.我在我的程序中使用Jnotify和JAVA Mail.
我得到的错误是,
javax.mail.MessagingException: IOException while sending message;
nested exception is:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type multipart/mixed; boundary="----=_Part_0_145238.1392728439484"
Run Code Online (Sandbox Code Playgroud)
我在stackoverflow中寻找了解决方案以寻求帮助,但没有一个在哪里有用.
提前致谢
public void fileCreated(int wd, String rootPath, String name) {
print("created " + rootPath + " : " + name);
if (name.contains(".apk"))
SendEmail(name);
else
System.out.println("Not the APK file");
}
void SendEmail(String strname){
String Path = "D:/POC/Email/apk folder/"+strname;
System.out.println("Path->" + Path);
Properties props = new Properties();
props.put("mail.smtp.host","173.194.78.108");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth","true");
props.put("mail.smtp.port","465");
System.out.println("Properties has been set properly");
Session session = …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Jenkins中执行命令shell,我正在使用Windows 7.在控制台输出中,我有这样的:
Building in workspace C:\Program Files (x86)\Jenkins\workspace\test
[test] $ sh -xe C:\Windows\TEMP\hudson6299483223982766034.sh
The system cannot find the file specified
FATAL: L'exécution de la commande a échoué.
java.io.IOException: Cannot run program "sh" (in directory "C:\Program Files (x86)\Jenkins\workspace\test"): CreateProcess error=2, Le fichier spécifié est introuvable
at java.lang.ProcessBuilder.start(Unknown Source)
at hudson.Proc$LocalProc.<init>(Proc.java:244)
at hudson.Proc$LocalProc.<init>(Proc.java:216)
at hudson.Launcher$LocalLauncher.launch(Launcher.java:816)
at hudson.Launcher$ProcStarter.start(Launcher.java:382)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:97)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:66)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:20)
at hudson.model.AbstractBuild$AbstractBuildExecution.perform(AbstractBuild.java:779)
at hudson.model.Build$BuildExecution.build(Build.java:205)
at hudson.model.Build$BuildExecution.doRun(Build.java:162)
at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:537)
at hudson.model.Run.execute(Run.java:1744)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:43)
at hudson.model.ResourceController.execute(ResourceController.java:98)
at hudson.model.Executor.run(Executor.java:374)
Caused by: java.io.IOException: …Run Code Online (Sandbox Code Playgroud) "可能出错的事情与不可能出错的事情之间的主要区别在于,当一件不可能出错的事情出错时,通常会发现无法进入或修复." -道格拉斯·亚当斯
我有一个类FileItems.FileItems构造函数接受一个文件,如果该文件不存在则抛出异常(FileNotFoundException).该类的其他方法也涉及文件操作,因此具有抛出FileNotFoundException的能力.我想找到一个更好的解决方案.一种解决方案,不需要其他程序员处理所有这些极不可能的FileNotFoundExceptions.
事情的事实:
代码目前看起来像这样
public Iterator getFileItemsIterator() {
try{
Scanner sc = new Scanner(this.fileWhichIsKnowToExist);
return new specialFileItemsIterator(sc);
} catch (FileNotFoundException e){ //can never happen}
return null;
}
Run Code Online (Sandbox Code Playgroud)
如何在不定义自定义未经检查的FileNotFoundException的情况下更好地完成此操作?有没有办法将checkedException转换为uncheckException?
在Tomcat上编写Grails应用程序时,我遇到了奇怪的问题.
创建简单的测试控制器后,我想在包com中编写测试内容
package com.domain.controller
import java.io.File;
import java.io.PrintWriter;
class TestController {
def index() {
// test
try {
PrintWriter writer = new PrintWriter("/home/user/domains/domain.com/public_html/the-file-name.txt");
writer.println("The first line");
writer.println("The second line");
writer.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
我得到一个例外:
类java.io.FileNotFoundException消息/home/user/domains/domain.com/public_html/the-file-name.txt(Brakdostępu)
我已将chmod设置为777 /home/user/domains/domain.com/public_html/.而且tomcat7.tomcat7是老板.我还尝试使用访问权限777和所有权设置为tomcat7创建此文件,但我仍然得到一个例外:
ls -al /home/user/domains/domain.com/public_html
razem 16
drwxrwxrwx 3 tomcat7 tomcat7 4096 01-08 23:25 .
drwxr-xr-x 8 user user 4096 12-16 17:14 ..
-rwxrwxrwx 1 tomcat7 tomcat7 0 01-08 23:25 the-file-name.txt
Run Code Online (Sandbox Code Playgroud)
我应该在OS中遇到什么条件?
如果有人能澄清问题,我将非常感激.
编辑 …