我在本地工作代码:
package task.com.helloworld;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button button;
TextView textView;
EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button)findViewById(R.id.button);
textView = (TextView)findViewById(R.id.textView6);
editText = (EditText)findViewById(R.id.editText);
final String name = editText.getText().toString();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// textView.setText("Hello "+name+", Welcome to Android. ");
if(TextUtils.isEmpty(name))
Toast.makeText(MainActivity.this, "Edit Text is Empty", Toast.LENGTH_LONG).show();
else
Toast.makeText(MainActivity.this, "Edit Text is not Empty", Toast.LENGTH_LONG).show();
}
});
}
}
然而,它不适用于Elastic Beanstalk。我的项目结构很简单:
URL resource = getClass().getClassLoader().getResource("static/config");
File configFolder = new File(resource.getFile());
for (File file : configFolder.listFiles()) {
//working with files
}
我试图记录我的能力。
/src
/main
/java
/...
/resources
/static
/config
1.json
2.json
...
...
我收到的是:
LOG.info(Optional.ofNullable(
getClass().getClassLoader().getResource("static/config"))
.map(URL::toString)
.orElse("null"));
因此应该存在 / static / config 文件夹。但我在这里得到了NPE:
jar:file:/var/app/current/application.jar!/WEB-INF/classes!/static/config
我应该以其他方式处理文件吗?在EC2实例下,文件结构是否存在差异?