throws

第十周课程总结

时间秒杀一切 提交于 2019-12-03 09:50:13
一、io流的三种分类方式 1.按流的方向分为:输入流和输出流 2.按流的数据单位不同分为:字节流和字符流 3.按流的功能不同分为:节点流和处理流 二、inputstream的基本方法 int read() throws ioexception 读取一个字节以整数形式返回,如果返回-1已到输入流的末尾 void close() throws ioexception 关闭流释放内存资源 long skip(long n) throws ioexception 跳过n个字节不读 outputstream的基本方法 void write(int b) throws ioexception 向输出流写入一个字节数据 void flush() throws ioexception 将输出流中缓冲的数据全部写出到目的地 三、io流的四大抽象类: 字符流: reader writer 字节流:inputstream(读数据) outputstream(写数据) 四、writer的基本方法 void write(int c) throws ioexception 向输出流写入一个字符数据 void write(string str) throws ioexception 将一个字符串中的字符写入到输出流 void write(string str,int offset,int length)

第十周课程总结

时光总嘲笑我的痴心妄想 提交于 2019-12-03 09:25:47
本周学习了javaIO。 File是唯一表示与文件本身有关的类,使用它可以进行创建或删除文件等操作。 File类的构造方法: public File(String pathname) -->实例化File的时候,必须设计好路径。 public static final String separator (Windows中表示路径的分隔符 "") 字节流 1.字节输出流:OutputStream OutputStream是整个IO包中字节输出溜的最大父类,此类的定义如下: public abstract class OutputStream extends Object implements Closeable, Flushable OutputStream类中常用的方法 1.public void close() throws IOException 关闭输出流 2.public void flush() throws IOException 刷新缓冲区 3.public void write(byte[] b) throws IOEception 将一个byte数组写入数据流 4.public void write (byte[] b, int off, int len) throws IOException 将一个指定范围的byte数组写入数据流 5.public

Qt application throws “dyld: Symbol not found: __cg_jpeg_resync_to_restart”

匿名 (未验证) 提交于 2019-12-03 08:57:35
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I get well known dyld issue on OS X. Qt.pro file: INCLUDEPATH += /usr/local/Cellar/libpng/1.6.23/include /usr/local/Cellar/jpeg/8d/include LIBS += -L/usr/local/Cellar/libpng/1.6.23/lib -L/usr/local/Cellar/jpeg/8d/lib -ljpeg -lpng -ljpeg -lz In runtime my application throws: dyld: Symbol not found: __cg_jpeg_resync_to_restart Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libTIFF.dylib Expected in: /usr/local/Cellar/jpeg/8d/lib/libjpeg.8.dylib in /System/Library/Frameworks/ImageIO.framework/Versions/A

MediaPlayer.prepare() throws IllegalStateException on Android L

匿名 (未验证) 提交于 2019-12-03 08:52:47
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have code that plays mp3 file from assets directory: MediaPlayer mediaPlayer = new MediaPlayer(); descriptor = context.getAssets().openFd("beep.mp3"); mediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength()); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mediaPlayer.setVolume(soundLevel, soundLevel); descriptor.close(); mediaPlayer.setLooping(false); mediaPlayer.prepare(); mediaPlayer.start(); This code was working fine on every device and every Android version. Until after

Unboxing a null boxed object throws unexpected NullPointerException

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: If you run the following code, public class Foo{ public static void main(String[] args){ int id = new Bar().getId(); // throws unexpected NullPointerException } private static class Bar{ private final Integer id; public Bar(){ this(null); } public Bar(Integer id){ this.id = id; } public Integer getId(){ return id; } } } you will get the following stacktrace, Exception in thread "main" java.lang.NullPointerException at Foo.main(Foo.java:3) How come there's no compiler warning or anything? IMHO it's a pretty nasty subtlety with unboxing, or

Java异常处理总结

有些话、适合烂在心里 提交于 2019-12-03 07:47:59
异常 (Exception):发生于程序执行期间,表明出现了一个非法的运行状况。许多JDK中的方法在检测到非法情况时,都会抛出一个异常对象。 例如:数组越界和被0除 异常处理的目的是依据实际情况提供不同的错误应对策略与手段,使程序更稳定,更安全。 异常处理的主要用途是提供准确的错误消息,解释失败的原因、位置和错误类型等,同时提供一定的恢复能力,尽可能地保证数据完整性不被破坏,并让程序能继续运行。 Java中的异常捕获语句: Try{ //可能发生运行错误的代码; } catch(异常类型 异常对象引用){ //用于处理异常的代码 } finally{ //用于“善后” 的代码 } Java 中所有可捕获的异常都派生自 Exception 类。 使用Java异常处理机制: 1.把可能会发生错误的代码放进try语句块中。 2.当程序检测到出现了一个错误时会抛出一个异常对象。异常处理代码会捕获并处理这个错误。 catch语句块中的代码用于处理错误。 3.当异常发生时,程序控制流程由try语句块跳转到catch语句块。 4.不管是否有异常发生,finally语句块中的语句始终保证被执行。 5.如果没有提供合适的异常处理代码,JVM将会结束掉整个应用程序。 Java中的异常分类: Throwable类有两个直接子类: Exception:出现的问题是可以被捕获的; Error:系统错误

第十周课程总结

对着背影说爱祢 提交于 2019-12-03 04:16:56
一.File类的基本操作介绍 1.File类的构造方法: public File(String pathname) //实例化File类的时候,必须设置好路径。 2.File类中的主要方法和常量 方法或常量 类型 描述 public static final String pathSeparator 常量 表示路径的分隔符(windows是:“;”) public static final String separator 常量 表示路径的分隔符(windows是:"\") public File(String pathname) 构造 创建File类对象,传入完整路径 public File(File parent,String child) 构造 根据指定的父路径创建子文件 public boolean creatNewFile() throws IOException 普通 创建新文件 public boolean delete() 普通 删除文件 public boolean exists() 普通 判断文件是否存在 public boolean isDirectory() 普通 判断给定的路径是否是一个目录 public long length() 普通 返回文件的大小 piblic String[] list() 普通 列出指定目录的全部内容,只是列出了名称

java.awt.Robot.keyPress throws IllegalArgumentException when when pressing quotation mark key

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: When you try to use Robot.keyPress to type a " (double quotation mark) it throws a java.lang.IllegalArgumentException: Invalid key code. How can I fix or get around this? If it helps, I am currently on Windows. Test code: import java.awt.Robot; import java.awt.event.KeyEvent; public class Test { public static void main(String[] args) throws Exception { Robot robot = new Robot(); try { robot.keyPress(KeyEvent.VK_QUOTEDBL); } catch (Exception e) { e.printStackTrace(); } } } Exception: java.lang.IllegalArgumentException: Invalid key code at sun

JAXB marshalling XMPP stanzas

匿名 (未验证) 提交于 2019-12-03 02:01:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am trying to marshall a message using the following snippet: JAXBContext jContext = JAXBContext . newInstance ( Iq . class ); Marshaller m = newJAXBContext . createMarshaller (); m . setProperty ( Marshaller . JAXB_FRAGMENT , Boolean . TRUE ); m . setProperty ( Marshaller . JAXB_FORMATTED_OUTPUT , true ); Bind bind = new Bind (); bind . setResource ( "resource" ); Iq iq = new Iq (); iq . setId ( iqId ); iq . setType ( "set" ); iq . getAnies (). add ( bind ); ByteArrayOutputStream baos = new ByteArrayOutputStream (); m . marshal (

Spring security antMatcher does not work

匿名 (未验证) 提交于 2019-12-03 01:39:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: EDIT: I further drilled down the problem and turns out issue persists even with single configuration. If I use single configuration and keep http.antMatcher("/api/test/**") urls don't get secured. Removing the antMatcher and antMatchers immediately secures the url. i.e if I use: http.httpBasic() .and() .authorizeRequests() .anyRequest() .authenticated(); then only spring security is securing url. Why isn't antMatcher functioning? (Updated the title to include actual issue.) Original Post: I have referred following stackoverflow questions: